mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 10:45:27 +00:00
fix help command
This commit is contained in:
parent
e4a408ff30
commit
2e9570b6be
|
@ -17,8 +17,9 @@ export default {
|
|||
name: 'ban',
|
||||
aliases: null,
|
||||
description: 'Ban a member from the server',
|
||||
syntax: '/ban @username [10m?] [reason?]',
|
||||
syntax: '/ban @username [10m|1h|...?] [reason?]',
|
||||
removeEmptyArgs: true,
|
||||
category: 'moderation',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!await isModerator(message.member!, message.serverContext))
|
||||
return message.reply(NO_MANAGER_MSG);
|
||||
|
|
|
@ -12,6 +12,7 @@ export default {
|
|||
aliases: [ 'admins', 'manager', 'managers' ],
|
||||
description: 'Allow users to control the bot\'s configuration',
|
||||
syntax: SYNTAX,
|
||||
category: 'configuration',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!hasPerm(message.member!, 'ManageServer'))
|
||||
return message.reply('You need **ManageServer** permission to use this command.');
|
||||
|
|
|
@ -12,6 +12,7 @@ export default {
|
|||
name: 'botctl',
|
||||
aliases: null,
|
||||
description: 'Perform administrative actions',
|
||||
category: 'configuration',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!isBotManager(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ import MessageCommandContext from "../../struct/MessageCommandContext";
|
|||
export default {
|
||||
name: 'debug',
|
||||
aliases: null,
|
||||
description: 'give info helpful for development and debugging',
|
||||
description: 'Gives info helpful for development and debugging',
|
||||
category: 'misc',
|
||||
run: (message: MessageCommandContext, args: string[]) => {
|
||||
message.reply(`Server ID: ${message.channel?.server_id || 'None'}\n`
|
||||
+ `Server context: ${message.serverContext._id} `
|
||||
|
|
|
@ -9,6 +9,7 @@ export default {
|
|||
description: 'Evaluate JS code',
|
||||
restrict: 'BOTOWNER',
|
||||
removeEmptyArgs: false,
|
||||
category: 'owner',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
let cmd = `let { client } = require("../..");`
|
||||
+ `let axios = require("axios").default;`
|
||||
|
|
|
@ -1,11 +1,111 @@
|
|||
import Command from "../../struct/Command";
|
||||
import { Message } from "revolt.js/dist/maps/Messages";
|
||||
import { commands, DEFAULT_PREFIX, ownerIDs } from "../modules/command_handler";
|
||||
import CommandCategory from "../../struct/CommandCategory";
|
||||
|
||||
const categories: { [key: string]: CommandCategory } = {
|
||||
'moderation': {
|
||||
friendlyName: 'Moderation',
|
||||
description: 'Moderation-focused commands',
|
||||
aliases: [ 'mod', 'mods' ],
|
||||
},
|
||||
'configuration': {
|
||||
friendlyName: 'Configuration',
|
||||
description: 'Configure AutoMod',
|
||||
aliases: [ 'conf', 'config' ],
|
||||
},
|
||||
'misc': {
|
||||
friendlyName: 'Misc',
|
||||
description: 'Random stuff :yed:',
|
||||
aliases: [ 'miscellaneous', 'weirdwordicantspell' ],
|
||||
},
|
||||
'owner': {
|
||||
friendlyName: 'Owner',
|
||||
description: 'Owner-only commands for managing AutoMod',
|
||||
aliases: [],
|
||||
},
|
||||
'uncategorized': {
|
||||
friendlyName: 'Uncategorized',
|
||||
description: 'Uncategorized commands',
|
||||
aliases: [],
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'help',
|
||||
aliases: null,
|
||||
description: 'help command i guess',
|
||||
run: (message: Message, args: string[]) => {
|
||||
message.reply(`command list can be found here kthxbay https://github.com/janderedev/revolt-automod/wiki/Bot-usage`);
|
||||
description: 'Help command.',
|
||||
removeEmptyArgs: true,
|
||||
category: 'misc',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
const isBotOwner = ownerIDs.includes(message.author_id);
|
||||
const prefix = DEFAULT_PREFIX; // TODO: fetch prefix from server config
|
||||
|
||||
let searchInput = args.shift()?.toLowerCase();
|
||||
if (!searchInput) {
|
||||
let msg = `## AutoMod help\n` +
|
||||
`Type **${prefix}help [category]** to view see all commands or **${prefix}help [command]** to learn more about a command.\n\n`;
|
||||
|
||||
let total = 0;
|
||||
|
||||
for (const categoryName in categories) {
|
||||
let cmdCount = commands.filter(
|
||||
cmd => ((cmd.category || 'uncategorized') == categoryName) &&
|
||||
(cmd.restrict == 'BOTOWNER' ? isBotOwner : true) // Ensure owner commands are only shown to bot owner
|
||||
).length;
|
||||
|
||||
if (cmdCount > 0) {
|
||||
total++;
|
||||
const category = categories[categoryName];
|
||||
msg += `**${category.friendlyName}**\n` +
|
||||
` \u200b \u200b ↳ ${(category.description)} \u200b $\\big |$ \u200b **${cmdCount}** command${cmdCount == 1 ? '' : 's'}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
msg += `\n##### Categories: ${total}`;
|
||||
|
||||
await message.reply(msg);
|
||||
} else {
|
||||
let [ categoryName, category ] = Object.entries(categories).find(
|
||||
c => c[1].friendlyName.toLowerCase() == searchInput
|
||||
|| c[0].toLowerCase() == searchInput
|
||||
) || Object.entries(categories).find(
|
||||
c => c[1].aliases.find(k => k.toLowerCase() == searchInput)
|
||||
) || [];
|
||||
if (category && !searchInput.startsWith(prefix)) {
|
||||
let msg = `**AutoMod help** - Category: ${category.friendlyName}\n`
|
||||
+ `${category.description}\n\n`
|
||||
+ `Type **${prefix}help [command]** to learn more about a command.\n\n`;
|
||||
|
||||
let cmdList = commands.filter(c => (c.category || 'uncategorized') == categoryName);
|
||||
if (cmdList.length > 0) {
|
||||
for (const cmd of cmdList) {
|
||||
msg += `**${prefix}${cmd.name}** \u200b $\\big |$ \u200b ${cmd.description}\n`;
|
||||
|
||||
msg += '\n';
|
||||
}
|
||||
|
||||
msg += `##### Total: ${cmdList.length}`;
|
||||
} else msg += `### This category is empty.`;
|
||||
|
||||
await message.reply(msg);
|
||||
} else {
|
||||
if (searchInput.startsWith(prefix)) searchInput = searchInput.substring(prefix.length);
|
||||
let cmd = commands.find(c => c.name.toLowerCase() == searchInput)
|
||||
|| commands.find(c => c.aliases && c.aliases.find(k => k.toLowerCase() == searchInput));
|
||||
|
||||
if (!cmd) {
|
||||
return message.reply(`I can't find any command or category matching \`${searchInput}\`.`);
|
||||
} else {
|
||||
let msg = `**AutoMod help** - Command: ${cmd.name}\n`
|
||||
+ `${cmd.description}\n\n`;
|
||||
|
||||
if (cmd.syntax) msg += `Syntax: \`${cmd.syntax}\`\n`;
|
||||
msg += 'Aliases: ' + (cmd.aliases ? `\`${cmd.aliases.join(`\`, \``)}\`` : 'None') + '\n';
|
||||
|
||||
message.reply(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} as Command;
|
||||
|
|
|
@ -14,6 +14,7 @@ export default {
|
|||
description: 'Eject a member from the server',
|
||||
syntax: '/kick @username [reason?]',
|
||||
removeEmptyArgs: true,
|
||||
category: 'moderation',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!await isModerator(message.member!, message.serverContext))
|
||||
return message.reply(NO_MANAGER_MSG);
|
||||
|
|
|
@ -15,6 +15,7 @@ export default {
|
|||
aliases: [ 'moderators', 'mod', 'mods' ],
|
||||
description: 'Allow users to moderate other users',
|
||||
syntax: SYNTAX,
|
||||
category: 'configuration',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!await isBotManager(message.member!, message.channel?.server!)) return message.reply(NO_MANAGER_MSG);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ export default {
|
|||
name: 'ping',
|
||||
aliases: null,
|
||||
description: 'ping pong',
|
||||
category: 'misc',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
let now = Date.now();
|
||||
message.reply(`Measuring...`)
|
||||
|
|
|
@ -11,8 +11,9 @@ const MENTION_TEXT = 'You can also @mention me instead of using the prefix.';
|
|||
export default {
|
||||
name: 'prefix',
|
||||
aliases: null,
|
||||
description: 'modify prefix',
|
||||
description: 'Configure AutoMod\'s prefix',
|
||||
syntax: SYNTAX,
|
||||
category: 'configuration',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
let config: ServerConfig = (await client.db.get('servers').findOne({ id: message.channel?.server_id })) ?? {};
|
||||
|
||||
|
|
|
@ -9,8 +9,9 @@ const MAX_PURGE_AMOUNT = 100;
|
|||
export default {
|
||||
name: 'purge',
|
||||
aliases: [ 'clear' ],
|
||||
description: 'delete multiple messages at once',
|
||||
description: 'Mass delete messages',
|
||||
syntax: SYNTAX,
|
||||
category: 'moderation',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
try {
|
||||
if (!message.member || !await isModerator(message.member!, message.channel?.server!)) return message.reply('🔒 Access denied');
|
||||
|
|
|
@ -11,11 +11,12 @@ import MessageCommandContext from "../../struct/MessageCommandContext";
|
|||
export default {
|
||||
name: 'settings',
|
||||
aliases: [ 'setting' ],
|
||||
description: 'change antispam settings',
|
||||
description: 'Manage AutoMod\'s configuration',
|
||||
category: 'configuration',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!isBotManager(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||
|
||||
return 'command is disabled for now';
|
||||
return 'This feature is currently disabled';
|
||||
|
||||
let settings = {
|
||||
spam: [
|
||||
|
|
|
@ -8,6 +8,7 @@ export default {
|
|||
description: 'Run code in a shell',
|
||||
restrict: 'BOTOWNER',
|
||||
removeEmptyArgs: false,
|
||||
category: 'owner',
|
||||
run: async (message: Message, args: string[]) => {
|
||||
let cmd = args.join(' ');
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@ import { Message } from "revolt.js/dist/maps/Messages";
|
|||
export default {
|
||||
name: 'test',
|
||||
aliases: [ 'testalias' ],
|
||||
description: 'epic test command',
|
||||
description: 'Test command',
|
||||
category: 'misc',
|
||||
run: (message: Message, args: string[]) => {
|
||||
message.reply('I am here');
|
||||
message.reply('Beep boop.');
|
||||
}
|
||||
} as Command;
|
||||
|
|
|
@ -11,6 +11,7 @@ export default {
|
|||
aliases: [ 'pardon' ],
|
||||
description: 'Unbans a user',
|
||||
syntax: '/unban [@user or ID]',
|
||||
category: 'moderation',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!isModerator(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ export default {
|
|||
aliases: null,
|
||||
removeEmptyArgs: false,
|
||||
description: 'add an infraction to an user\'s record',
|
||||
category: 'moderation',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!await isModerator(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||
let user = await parseUserOrId(args.shift() ?? '');
|
||||
|
|
|
@ -16,6 +16,7 @@ export default {
|
|||
aliases: [ 'warnings', 'infractions', 'infraction' ],
|
||||
description: 'Show all user infractions',
|
||||
syntax: '/warns; /warns @username ["export-csv"]; /warns rm [ID]',
|
||||
category: 'moderation',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
if (!await isModerator(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@ import MessageCommandContext from "../../struct/MessageCommandContext";
|
|||
import ServerConfig from "../../struct/ServerConfig";
|
||||
import { isBotManager, NO_MANAGER_MSG, parseUser } from "../util";
|
||||
|
||||
const SYNTAX = '';
|
||||
const SYNTAX = '/whitelist add @user; /whitelist remove @user; /whitelist list';
|
||||
|
||||
export default {
|
||||
name: 'whitelist',
|
||||
aliases: [],
|
||||
description: 'Allow users or roles to bypass moderation rules',
|
||||
syntax: SYNTAX,
|
||||
category: 'configuration',
|
||||
run: async (message: MessageCommandContext, args: string[]) => {
|
||||
let config: ServerConfig = await client.db.get('servers').findOne({ id: message.serverContext._id }) || {}
|
||||
if (!config.whitelist) config.whitelist = { users: [], roles: [], managers: true }
|
||||
|
|
|
@ -13,13 +13,16 @@ import { fileURLToPath } from 'url';
|
|||
const filename = fileURLToPath(import.meta.url);
|
||||
const dirname = path.dirname(filename);
|
||||
|
||||
const ownerIDs = process.env['BOT_OWNERS'] ? process.env['BOT_OWNERS'].split(',') : [];
|
||||
const DEFAULT_PREFIX = process.env['PREFIX']
|
||||
?? process.env['BOT_PREFIX']
|
||||
?? process.env['COMMAND_PREFIX']
|
||||
?? '/';
|
||||
|
||||
let commands: Command[];
|
||||
|
||||
(async () => {
|
||||
let commands: Command[] = (await Promise.all(
|
||||
commands = (await Promise.all(
|
||||
fs.readdirSync(path.join(dirname, '..', 'commands'))
|
||||
.filter(file => file.endsWith('.js'))
|
||||
.map(async file => await import(path.join(dirname, '..', 'commands', file)) as Command)
|
||||
|
@ -43,10 +46,10 @@ const DEFAULT_PREFIX = process.env['PREFIX']
|
|||
let guildPrefix = config.prefix ?? DEFAULT_PREFIX;
|
||||
|
||||
if (cmdName.startsWith(`<@${client.user?._id}>`)) {
|
||||
cmdName = cmdName.substr(`<@${client.user?._id}>`.length);
|
||||
cmdName = cmdName.substring(`<@${client.user?._id}>`.length);
|
||||
if (!cmdName) cmdName = args.shift() ?? ''; // Space between mention and command name
|
||||
} else if (cmdName.startsWith(guildPrefix)) {
|
||||
cmdName = cmdName.substr(guildPrefix.length);
|
||||
cmdName = cmdName.substring(guildPrefix.length);
|
||||
if (config.spaceAfterPrefix && !cmdName) cmdName = args.shift() ?? '';
|
||||
} else return;
|
||||
|
||||
|
@ -55,7 +58,6 @@ const DEFAULT_PREFIX = process.env['PREFIX']
|
|||
let cmd = commands.find(c => c.name == cmdName || (c.aliases?.indexOf(cmdName!) ?? -1) > -1);
|
||||
if (!cmd) return;
|
||||
|
||||
let ownerIDs = process.env['BOT_OWNERS'] ? process.env['BOT_OWNERS'].split(',') : [];
|
||||
if (cmd.restrict == 'BOTOWNER' && ownerIDs.indexOf(msg.author_id) == -1) {
|
||||
logger.warn(`User ${msg.author?.username} tried to run owner-only command: ${cmdName}`);
|
||||
msg.reply('🔒 Access denied');
|
||||
|
@ -95,4 +97,4 @@ const DEFAULT_PREFIX = process.env['PREFIX']
|
|||
});
|
||||
})();
|
||||
|
||||
export { DEFAULT_PREFIX }
|
||||
export { DEFAULT_PREFIX, commands, ownerIDs }
|
||||
|
|
|
@ -6,6 +6,7 @@ class Command {
|
|||
restrict?: 'BOTOWNER' | null;
|
||||
removeEmptyArgs?: boolean | null;
|
||||
run: Function;
|
||||
category?: string;
|
||||
}
|
||||
|
||||
export default Command;
|
||||
|
|
7
src/struct/CommandCategory.ts
Normal file
7
src/struct/CommandCategory.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
class CommandCategory {
|
||||
friendlyName: string;
|
||||
description: string;
|
||||
aliases: string[];
|
||||
}
|
||||
|
||||
export default CommandCategory;
|
Loading…
Reference in a new issue