Remove some now unused blacklist functionality

This commit is contained in:
Declan Chidlow 2024-07-13 19:26:04 +08:00
parent 3111c35b98
commit adcf1b73cf
2 changed files with 262 additions and 328 deletions

View file

@ -9,351 +9,285 @@ import { checkMessageForFilteredWords } from "../../modules/antispam";
import { DEFAULT_PREFIX } from "../../modules/command_handler"; import { DEFAULT_PREFIX } from "../../modules/command_handler";
import { embed, EmbedColor, getDmChannel, isBotManager, NO_MANAGER_MSG, sanitizeMessageContent } from "../../util"; import { embed, EmbedColor, getDmChannel, isBotManager, NO_MANAGER_MSG, sanitizeMessageContent } from "../../util";
const WORDLIST_DEFAULT_MESSAGE = '<@{{user_id}}>, the message you sent contained a blocked word.'; const WORDLIST_DEFAULT_MESSAGE = "<@{{user_id}}>, the message you sent contained a blocked word.";
export default { export default {
name: 'botctl', name: "botctl",
aliases: null, aliases: null,
description: 'Perform administrative actions', description: "Perform administrative actions",
category: CommandCategory.Config, category: CommandCategory.Config,
run: async (message: MessageCommandContext, args: string[]) => { run: async (message: MessageCommandContext, args: string[]) => {
if (!await isBotManager(message)) return message.reply(NO_MANAGER_MSG); if (!(await isBotManager(message))) return message.reply(NO_MANAGER_MSG);
try { try {
let action = args.shift(); let action = args.shift();
switch(action) { switch (action) {
case 'ignore_blacklist': { case "spam_detection": {
if (args[0] == 'yes') { if (args[0] == "on") {
if (message.serverContext.discoverable) { await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { antispamEnabled: true } });
return message.reply('Your server is currently listed in server discovery. As part of Revolt\'s [Discover Guidelines](<https://support.revolt.chat/kb/safety/discover-guidelines>), all servers on Discover are enrolled to AutoMod\'s antispam features.'); await message.reply("Spam detection is now enabled in this server.\n" + "Please make sure AutoMod has permission to Manage Messages");
} } else if (args[0] == "off") {
if (message.serverContext.discoverable) {
return message.reply(
"Your server is currently listed in server discovery. As part of Revolt's [Discover Guidelines](<https://support.revolt.chat/kb/safety/discover-guidelines>), all servers on Discover are enrolled to AutoMod's antispam features.",
);
}
await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { allowBlacklistedUsers: true } }); await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { antispamEnabled: false } });
await message.reply('Globally blacklisted users will no longer get banned in this server. Previously banned users will need to be unbanned manually.'); await message.reply("Spam detection is now disabled in this server.");
} else if (args[0] == 'no') { } else {
await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { allowBlacklistedUsers: false } }); const cfg = await dbs.SERVERS.findOne({ id: message.serverContext.id });
await message.reply('Globally blacklisted users will now get banned in this server.'); await message.reply(`Spam detection is currently **${cfg?.antispamEnabled ? "enabled" : "disabled"}**. ` + `Please specify either 'on' or 'off' to toggle this setting.`);
} else { }
await message.reply(`Please specify either 'yes' or 'no' to toggle this setting.`); break;
} }
break;
}
case 'spam_detection': { case "logs": {
if (args[0] == 'on') { if (!args[0]) {
await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { antispamEnabled: true } }); return await message.reply(`No category specified. Syntax: ${DEFAULT_PREFIX}botctl logs [category] [#channel]\n` + `Categories: \`messageupdate\`, \`modaction\``);
await message.reply('Spam detection is now enabled in this server.\nIf a user is wrongfully 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') {
if (message.serverContext.discoverable) {
return message.reply('Your server is currently listed in server discovery. As part of Revolt\'s [Discover Guidelines](<https://support.revolt.chat/kb/safety/discover-guidelines>), all servers on Discover are enrolled to AutoMod\'s antispam features.');
}
await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { antispamEnabled: false } }); if (!args[1]) {
await message.reply('Spam detection is now disabled in this server.'); return await message.reply("No target channel specified.");
}
} else { let channelInput = args[1];
const cfg = await dbs.SERVERS.findOne({ id: message.serverContext.id }); if (channelInput.startsWith("<#") && channelInput.endsWith(">")) {
await message.reply(`Spam detection is currently **${cfg?.antispamEnabled ? 'enabled' : 'disabled'}**. ` channelInput = channelInput.substring(2, channelInput.length - 1);
+ `Please specify either 'on' or 'off' to toggle this setting.`); }
}
break;
}
case 'logs': { const channel = client.channels.get(channelInput);
if (!args[0]) { if (!channel) return message.reply("I can't find that channel.");
return await message.reply( if (channel.serverId != message.channel?.serverId) return message.reply("That channel is not part of this server!");
`No category specified. Syntax: ${DEFAULT_PREFIX}botctl logs [category] [#channel]\n` + if (!channel.havePermission("SendMessage")) return message.reply("I don't have permission to **send messages** in that channel.");
`Categories: \`messageupdate\`, \`modaction\``, if (!channel.havePermission("SendEmbeds")) return message.reply("I don't have permission to **send embeds** in that channel.");
);
}
if (!args[1]) { switch (args[0]?.toLowerCase()) {
return await message.reply('No target channel specified.'); case "messageupdate": {
} await dbs.SERVERS.update(
{ id: message.channel!.serverId! },
{
$set: {
"logs.messageUpdate.revolt": {
channel: channel.id,
type: "EMBED",
},
},
$setOnInsert: {
id: message.channel!.serverId!,
},
},
{ upsert: true },
);
await message.reply(`Bound message update logs to <#${channel.id}>!`);
break;
}
let channelInput = args[1]; case "modaction": {
if (channelInput.startsWith('<#') && channelInput.endsWith('>')) { await dbs.SERVERS.update(
channelInput = channelInput.substring(2, channelInput.length - 1); { id: message.channel!.serverId! },
} {
$set: {
"logs.modAction.revolt": {
channel: channel.id,
type: "EMBED",
},
},
$setOnInsert: {
id: message.channel!.serverId!,
},
},
{ upsert: true },
);
await message.reply(`Bound moderation logs to <#${channel.id}>!`);
break;
}
const channel = client.channels.get(channelInput); default: {
if (!channel) return message.reply('I can\'t find that channel.'); return await message.reply("Unknown log category");
if (channel.serverId != message.channel?.serverId) return message.reply('That channel is not part of this server!'); }
if (!channel.havePermission('SendMessage')) return message.reply('I don\'t have permission to **send messages** in that channel.'); }
if (!channel.havePermission('SendEmbeds')) return message.reply('I don\'t have permission to **send embeds** in that channel.'); break;
}
switch(args[0]?.toLowerCase()) { case "filter": {
case 'messageupdate': { const config = await dbs.SERVERS.findOne({ id: message.channel!.serverId! });
await dbs.SERVERS.update( switch (args.shift()?.toLowerCase()) {
{ id: message.channel!.serverId! }, case "enable": {
{ await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $set: { wordlistEnabled: true } }, { upsert: true });
$set: { await message.reply({ embeds: [embed(`### Word filter enabled!\nThere are currently ${config?.wordlist?.length ?? 0} words on your list.`, null, EmbedColor.Success)] });
'logs.messageUpdate.revolt': { break;
channel: channel.id, }
type: 'EMBED', case "disable": {
}, await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $set: { wordlistEnabled: false } }, { upsert: true });
}, await message.reply({ embeds: [embed("Word filter disabled.", null, EmbedColor.SoftError)] });
$setOnInsert: { break;
id: message.channel!.serverId!, }
} case "add": {
}, let strictness: any = "HARD";
{ upsert: true }, if (["soft", "hard", "strict"].includes(args[0].toLowerCase())) {
); strictness = args.shift()!.toUpperCase() as any;
await message.reply(`Bound message update logs to <#${channel.id}>!`); }
break;
}
case 'modaction': { const word = args.join(" ").toLowerCase();
await dbs.SERVERS.update( if (!word) return message.reply("You didn't provide a word to add to the list!");
{ id: message.channel!.serverId! }, if (config?.wordlist?.find((w) => w.word == word)) return await message.reply("That word is already on the list!");
{
$set: {
'logs.modAction.revolt': {
channel: channel.id,
type: 'EMBED',
},
},
$setOnInsert: {
id: message.channel!.serverId!,
}
},
{ upsert: true },
);
await message.reply(`Bound moderation logs to <#${channel.id}>!`);
break;
}
default: { await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $push: { wordlist: { strictness, word } } }, { upsert: true });
return await message.reply('Unknown log category'); await message.reply({ embeds: [embed(`Word added with strictness **${strictness}**.`, null, EmbedColor.Success)] });
} break;
} }
break; case "remove": {
} const word = args.join(" ").toLowerCase();
if (!word) return message.reply("You need to provide the word to remove from the list.");
case 'filter': { if (!config?.wordlist?.find((w) => w.word == word)) return await message.reply("That word is not on the list.");
const config = await dbs.SERVERS.findOne({ id: message.channel!.serverId! }); await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $pull: { wordlist: { word } } }, { upsert: true });
switch(args.shift()?.toLowerCase()) { await message.reply({ embeds: [embed(`Word removed.`, null, EmbedColor.Success)] });
case 'enable': { break;
await dbs.SERVERS.update( }
{ id: message.channel!.serverId! }, case "show": {
{ $set: { wordlistEnabled: true } }, const formData = new FormData();
{ upsert: true }, formData.append(`wordlist_${message.channel?.serverId}`, config?.wordlist?.map((w) => `${w.strictness}\t${w.word}`).join("\n") ?? "", `wordlist_${message.channel?.serverId}.txt`);
);
await message.reply({ embeds: [
embed(
`### Word filter enabled!\nThere are currently ${config?.wordlist?.length ?? 0} words on your list.`,
null,
EmbedColor.Success
),
] });
break;
}
case 'disable': {
await dbs.SERVERS.update(
{ id: message.channel!.serverId! },
{ $set: { wordlistEnabled: false } },
{ upsert: true },
);
await message.reply({ embeds: [
embed('Word filter disabled.', null, EmbedColor.SoftError),
] });
break;
}
case 'add': {
let strictness: any = 'HARD';
if (['soft', 'hard', 'strict'].includes(args[0].toLowerCase())) {
strictness = args.shift()!.toUpperCase() as any;
}
const word = args.join(' ').toLowerCase(); try {
if (!word) return message.reply('You didn\'t provide a word to add to the list!'); const channel = await getDmChannel(message.authorId!);
if (config?.wordlist?.find(w => w.word == word)) return await message.reply('That word is already on the list!'); const res = await axios.post(`${client.configuration?.features.autumn.url}/attachments`, formData, { headers: formData.getHeaders(), responseType: "json" });
await channel.sendMessage({
attachments: [(res.data as any).id],
embeds: [embed(`Here's the current word list for **${message.channel?.server?.name}**.`, "Word List", EmbedColor.Success)],
});
await message.reply({ embeds: [embed(`I have sent the current word list to your direct messages!`, null, EmbedColor.Success)] });
} catch (e) {
console.error(e);
}
break;
}
case "message": {
const msg = args.join(" ");
if (!msg) {
return await message.reply({
embeds: [
embed(
"This command lets you change the message the bot will send if a message is filtered.\n" +
"Note that this message will not be sent if the configured action is to log events only.\n" +
"The current message is:\n" +
`>${sanitizeMessageContent(config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE)
.trim()
.replace(/\n/g, "\n>")}\n` +
"`{{user_id}}` will be substituted for the target user's ID.",
"Warning message",
EmbedColor.Success,
),
],
});
}
await dbs.SERVERS.update( await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $set: { wordlistAction: { action: config?.wordlistAction?.action ?? "LOG", message: msg } } }, { upsert: true });
{ id: message.channel!.serverId! }, await message.reply({ embeds: [embed("Filter message set!", null, EmbedColor.Success)] });
{ $push: { wordlist: { strictness, word } } }, break;
{ upsert: true }, }
); case "action": {
await message.reply({ embeds: [ let action: string;
embed(`Word added with strictness **${strictness}**.`, null, EmbedColor.Success), switch (args[0]?.toLowerCase()) {
] }); case "log":
break; case "delete":
} case "warn":
case 'remove': { action = args[0].toUpperCase();
const word = args.join(' ').toLowerCase(); break;
if (!word) return message.reply('You need to provide the word to remove from the list.'); default:
await message.reply({
embeds: [
embed(
"Please provide one of the following arguments:\n" +
"- **log** (Log the message in mod action log channel)\n" +
"- **delete** (Log and delete the message)\n" +
"- **warn** (Log and delete message, warn user)\n\n" +
`The currently configured action is **${config?.wordlistAction?.action ?? "LOG"}**.`,
null,
EmbedColor.SoftError,
),
],
});
return;
}
if (!config?.wordlist?.find(w => w.word == word)) return await message.reply('That word is not on the list.'); await dbs.SERVERS.update(
await dbs.SERVERS.update( { id: message.channel!.serverId! },
{ id: message.channel!.serverId! }, {
{ $pull: { wordlist: { word } } }, $set: {
{ upsert: true }, wordlistAction: {
); action: action as any,
await message.reply({ embeds: [ message: config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE,
embed(`Word removed.`, null, EmbedColor.Success), },
] }); },
break; },
} { upsert: true },
case 'show': { );
const formData = new FormData(); await message.reply({
formData.append( embeds: [embed(`Filter action set to **${action}**. ` + `Please make sure you configured a logging channel using **${DEFAULT_PREFIX}botctl logs**.`, null, EmbedColor.Success)],
`wordlist_${message.channel?.serverId}`, });
config?.wordlist?.map(w => `${w.strictness}\t${w.word}`).join('\n') ?? '', break;
`wordlist_${message.channel?.serverId}.txt` }
); case "test": {
const match = checkMessageForFilteredWords(args.join(" "), config as ServerConfig);
await message.reply({
embeds: [
match
? embed("Your word list matches this test phrase!", "Filter Test", EmbedColor.SoftError)
: embed("Your word list does not match this test phrase!", "Filter Test", EmbedColor.Success),
],
});
break;
}
default: {
await message.reply({
embeds: [
embed(
`### This command allows you to configure a manual word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter enable** - Enable the word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter disable** - Disable the word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter add [soft|hard|strict] [word]** - Add a word to the list. If omitted, defaults to 'hard'.\n` +
`- **${DEFAULT_PREFIX}botctl filter remove** - Remove a word from the list.\n` +
`- **${DEFAULT_PREFIX}botctl filter show** - Send the current filter list.\n` +
`- **${DEFAULT_PREFIX}botctl filter message [message]** - Set the message sent when a message is matched.\n` +
`- **${DEFAULT_PREFIX}botctl filter action [log|delete|warn]** - Configure the action taken on filtered messages.\n` +
`- **${DEFAULT_PREFIX}botctl filter test [phrase]** - Test whether a phrase matches your word list.\n` +
`More documentation can be found [here](https://github.com/sussycatgirl/automod/wiki/Word-Filter).`,
"Word filter",
),
embed(
`**Enabled:** ${!!config?.wordlistEnabled}` +
(!config?.wordlistEnabled
? ""
: `\n**Action:** ${config?.wordlistAction?.action ?? "LOG"}\n` +
`**Warning message:** ${config?.wordlistAction?.message}\n` +
`**Wordlist length:** ${config?.wordlist?.length ?? 0}`),
"Current configuration",
config?.wordlistEnabled ? EmbedColor.Success : EmbedColor.SoftError,
),
],
});
break;
}
}
break;
}
try { case undefined:
const channel = await getDmChannel(message.authorId!); case "":
const res = await axios.post( message.reply(
`${client.configuration?.features.autumn.url}/attachments`, `### Available subcommands\n` + `- \`spam_detection\` - Toggle automatic spam detection.\n` + `- \`logs\` - Configure log channels.\n` + `- \`filter\` - Configure word filter.\n`,
formData, );
{ headers: formData.getHeaders(), responseType: 'json' } break;
); default:
await channel.sendMessage({ message.reply(`Unknown option`);
attachments: [ (res.data as any).id ], }
embeds: [ embed( } catch (e) {
`Here's the current word list for **${message.channel?.server?.name}**.`, console.error("" + e);
'Word List', message.reply("Something went wrong: " + e);
EmbedColor.Success }
) ], },
});
await message.reply({ embeds: [
embed(`I have sent the current word list to your direct messages!`, null, EmbedColor.Success),
] });
} catch(e) {
console.error(e);
}
break;
}
case 'message': {
const msg = args.join(' ');
if (!msg) {
return await message.reply({ embeds: [
embed(
'This command lets you change the message the bot will send if a message is filtered.\n' +
'Note that this message will not be sent if the configured action is to log events only.\n' +
'The current message is:\n' +
`>${sanitizeMessageContent(config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE).trim().replace(/\n/g, '\n>')}\n` +
'`{{user_id}}` will be substituted for the target user\'s ID.',
'Warning message',
EmbedColor.Success
),
] });
}
await dbs.SERVERS.update(
{ id: message.channel!.serverId! },
{ $set: { wordlistAction: { action: config?.wordlistAction?.action ?? 'LOG', message: msg } } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(
'Filter message set!',
null,
EmbedColor.Success
),
] });
break;
}
case 'action': {
let action: string;
switch(args[0]?.toLowerCase()) {
case 'log':
case 'delete':
case 'warn':
action = args[0].toUpperCase();
break;
default:
await message.reply({ embeds: [
embed(
'Please provide one of the following arguments:\n' +
'- **log** (Log the message in mod action log channel)\n' +
'- **delete** (Log and delete the message)\n' +
'- **warn** (Log and delete message, warn user)\n\n' +
`The currently configured action is **${config?.wordlistAction?.action ?? 'LOG'}**.`,
null,
EmbedColor.SoftError
),
] });
return;
}
await dbs.SERVERS.update(
{ id: message.channel!.serverId! },
{ $set: { wordlistAction: {
action: action as any,
message: config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE
} } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(
`Filter action set to **${action}**. ` +
`Please make sure you configured a logging channel using **${DEFAULT_PREFIX}botctl logs**.`,
null,
EmbedColor.Success
),
] });
break;
}
case 'test': {
const match = checkMessageForFilteredWords(args.join(' '), config as ServerConfig);
await message.reply({ embeds: [
match
? embed('Your word list matches this test phrase!', 'Filter Test', EmbedColor.SoftError)
: embed('Your word list does not match this test phrase!', 'Filter Test', EmbedColor.Success)
] });
break;
}
default: {
await message.reply({ embeds: [
embed(
`### This command allows you to configure a manual word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter enable** - Enable the word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter disable** - Disable the word filter.\n` +
`- **${DEFAULT_PREFIX}botctl filter add [soft|hard|strict] [word]** - Add a word to the list. If omitted, defaults to 'hard'.\n` +
`- **${DEFAULT_PREFIX}botctl filter remove** - Remove a word from the list.\n` +
`- **${DEFAULT_PREFIX}botctl filter show** - Send the current filter list.\n` +
`- **${DEFAULT_PREFIX}botctl filter message [message]** - Set the message sent when a message is matched.\n` +
`- **${DEFAULT_PREFIX}botctl filter action [log|delete|warn]** - Configure the action taken on filtered messages.\n` +
`- **${DEFAULT_PREFIX}botctl filter test [phrase]** - Test whether a phrase matches your word list.\n` +
`More documentation can be found [here](https://github.com/sussycatgirl/automod/wiki/Word-Filter).`,
'Word filter',
),
embed(
`**Enabled:** ${!!config?.wordlistEnabled}` + (!config?.wordlistEnabled
? ''
: `\n**Action:** ${config?.wordlistAction?.action ?? 'LOG'}\n` +
`**Warning message:** ${config?.wordlistAction?.message}\n` +
`**Wordlist length:** ${config?.wordlist?.length ?? 0}`),
'Current configuration',
config?.wordlistEnabled ? EmbedColor.Success : EmbedColor.SoftError,
),
] });
break;
}
}
break;
}
case undefined:
case '':
message.reply(`### Available subcommands\n`
+ `- \`ignore_blacklist\` - Ignore the bot's global blacklist.\n`
+ `- \`spam_detection\` - Toggle automatic spam detection.\n`
+ `- \`logs\` - Configure log channels.\n`
+ `- \`filter\` - Configure word filter.\n`);
break
default:
message.reply(`Unknown option`);
}
} catch(e) {
console.error(''+e);
message.reply('Something went wrong: ' + e);
}
}
} as SimpleCommand; } as SimpleCommand;
export { WORDLIST_DEFAULT_MESSAGE } export { WORDLIST_DEFAULT_MESSAGE };

View file

@ -23,7 +23,7 @@ const categories: {
[CommandCategory.Owner]: { [CommandCategory.Owner]: {
friendlyName: "Owner", friendlyName: "Owner",
description: "Owner-only commands for managing AutoMod", description: "Owner-only commands for managing AutoMod",
aliases: [ "owner" ], aliases: ["owner"],
}, },
[CommandCategory.Miscellaneous]: { [CommandCategory.Miscellaneous]: {
friendlyName: "Miscellaneous", friendlyName: "Miscellaneous",