allow toggling spam detection

This commit is contained in:
JandereDev 2022-07-23 10:45:28 +02:00
parent 3c45dd110c
commit 7062d8e469
No known key found for this signature in database
GPG key ID: 5D5E18ACB990F57A
2 changed files with 38 additions and 18 deletions

View file

@ -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;

Binary file not shown.