diff --git a/bot/src/bot/commands/configuration/botctl.ts b/bot/src/bot/commands/configuration/botctl.ts index 265e351..36fab5c 100644 --- a/bot/src/bot/commands/configuration/botctl.ts +++ b/bot/src/bot/commands/configuration/botctl.ts @@ -10,34 +10,54 @@ export default { description: 'Perform administrative actions', category: CommandCategory.Config, run: async (message: MessageCommandContext, args: string[]) => { - if (!isBotManager(message)) return message.reply(NO_MANAGER_MSG); + if (!await isBotManager(message)) return message.reply(NO_MANAGER_MSG); + try { let action = args.shift(); switch(action) { - case 'ignore_blacklist': - try { - if (args[0] == 'yes') { - await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { allowBlacklistedUsers: true } }); - await message.reply('Globally blacklisted users will no longer get banned in this server. Previously banned users will need to be unbanned manually.'); - } else if (args[0] == 'no') { - await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { allowBlacklistedUsers: false } }); - await message.reply('Globally blacklisted users will now get banned in this server.'); - } else { - await message.reply(`Please specify either 'yes' or 'no' to toggle this setting.`); - } - } catch(e) { - console.error(''+e); - message.reply('Something went wrong: ' + e); + case 'ignore_blacklist': { + if (args[0] == 'yes') { + await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { allowBlacklistedUsers: true } }); + await message.reply('Globally blacklisted users will no longer get banned in this server. Previously banned users will need to be unbanned manually.'); + } else if (args[0] == 'no') { + await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { allowBlacklistedUsers: false } }); + await message.reply('Globally blacklisted users will now get banned in this server.'); + } else { + await message.reply(`Please specify either 'yes' or 'no' to toggle this setting.`); } - break; + break; + } + + case 'spam_detection': { + if (args[0] == 'on') { + await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { antispamEnabled: true } }); + await message.reply('Spam detection is now enabled in this server.\nIf a user wrongfully gets kicked ' + + 'or banned, please report it here: https://rvlt.gg/jan\n\n' + + 'Please make sure to grant AutoMod permission to **Kick**, **Ban** and **Manage Messages**!'); + } else if (args[0] == 'off') { + await dbs.SERVERS.update({ id: message.serverContext._id }, { $set: { antispamEnabled: false } }); + await message.reply('Spam detection is now disabled in this server.'); + + } else { + const cfg = await dbs.SERVERS.findOne({ id: message.serverContext._id }); + await message.reply(`Spam detection is currently **${cfg?.antispamEnabled ? 'enabled' : 'disabled'}**. ` + + `Please specify either 'on' or 'off' to toggle this setting.`); + } + break; + } case undefined: - case '': + case '': message.reply(`### Available subcommands\n` - + `- \`ignore_blacklist\` - Ignore the bot's global blacklist.`); + + `- \`ignore_blacklist\` - Ignore the bot's global blacklist.\n` + + `- \`spam_detection\` - Toggle automatic spam detection.\n`); break default: message.reply(`Unknown option`); + } + } catch(e) { + console.error(''+e); + message.reply('Something went wrong: ' + e); } } } as SimpleCommand; diff --git a/lib/.yarn/install-state.gz b/lib/.yarn/install-state.gz index 0ae979a..482088b 100644 Binary files a/lib/.yarn/install-state.gz and b/lib/.yarn/install-state.gz differ