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,95 +9,73 @@ 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) {
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 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;
}
case 'spam_detection': {
if (args[0] == 'on') {
await dbs.SERVERS.update({ id: message.serverContext.id }, { $set: { antispamEnabled: true } }); 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 is wrongfully kicked ' await message.reply("Spam detection is now enabled in this server.\n" + "Please make sure AutoMod has permission to Manage Messages");
+ 'or banned, please report it here: https://rvlt.gg/jan\n\n' } else if (args[0] == "off") {
+ 'Please make sure to grant AutoMod permission to **Kick**, **Ban** and **Manage Messages**!');
} else if (args[0] == 'off') {
if (message.serverContext.discoverable) { 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.'); 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 } });
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 'logs': {
if (!args[0]) {
return await message.reply(
`No category specified. Syntax: ${DEFAULT_PREFIX}botctl logs [category] [#channel]\n` +
`Categories: \`messageupdate\`, \`modaction\``,
); );
} }
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 "logs": {
if (!args[0]) {
return await message.reply(`No category specified. Syntax: ${DEFAULT_PREFIX}botctl logs [category] [#channel]\n` + `Categories: \`messageupdate\`, \`modaction\``);
}
if (!args[1]) { if (!args[1]) {
return await message.reply('No target channel specified.'); return await message.reply("No target channel specified.");
} }
let channelInput = args[1]; let channelInput = args[1];
if (channelInput.startsWith('<#') && channelInput.endsWith('>')) { if (channelInput.startsWith("<#") && channelInput.endsWith(">")) {
channelInput = channelInput.substring(2, channelInput.length - 1); channelInput = channelInput.substring(2, channelInput.length - 1);
} }
const channel = client.channels.get(channelInput); const channel = client.channels.get(channelInput);
if (!channel) return message.reply('I can\'t find that channel.'); if (!channel) return message.reply("I can't find that channel.");
if (channel.serverId != message.channel?.serverId) return message.reply('That channel is not part of this server!'); 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("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.'); if (!channel.havePermission("SendEmbeds")) return message.reply("I don't have permission to **send embeds** in that channel.");
switch (args[0]?.toLowerCase()) { switch (args[0]?.toLowerCase()) {
case 'messageupdate': { case "messageupdate": {
await dbs.SERVERS.update( await dbs.SERVERS.update(
{ id: message.channel!.serverId! }, { id: message.channel!.serverId! },
{ {
$set: { $set: {
'logs.messageUpdate.revolt': { "logs.messageUpdate.revolt": {
channel: channel.id, channel: channel.id,
type: 'EMBED', type: "EMBED",
}, },
}, },
$setOnInsert: { $setOnInsert: {
id: message.channel!.serverId!, id: message.channel!.serverId!,
} },
}, },
{ upsert: true }, { upsert: true },
); );
@ -105,19 +83,19 @@ export default {
break; break;
} }
case 'modaction': { case "modaction": {
await dbs.SERVERS.update( await dbs.SERVERS.update(
{ id: message.channel!.serverId! }, { id: message.channel!.serverId! },
{ {
$set: { $set: {
'logs.modAction.revolt': { "logs.modAction.revolt": {
channel: channel.id, channel: channel.id,
type: 'EMBED', type: "EMBED",
}, },
}, },
$setOnInsert: { $setOnInsert: {
id: message.channel!.serverId!, id: message.channel!.serverId!,
} },
}, },
{ upsert: true }, { upsert: true },
); );
@ -126,189 +104,145 @@ export default {
} }
default: { default: {
return await message.reply('Unknown log category'); return await message.reply("Unknown log category");
} }
} }
break; break;
} }
case 'filter': { case "filter": {
const config = await dbs.SERVERS.findOne({ id: message.channel!.serverId! }); const config = await dbs.SERVERS.findOne({ id: message.channel!.serverId! });
switch (args.shift()?.toLowerCase()) { switch (args.shift()?.toLowerCase()) {
case 'enable': { case "enable": {
await dbs.SERVERS.update( await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $set: { wordlistEnabled: true } }, { upsert: true });
{ id: message.channel!.serverId! }, await message.reply({ embeds: [embed(`### Word filter enabled!\nThere are currently ${config?.wordlist?.length ?? 0} words on your list.`, null, EmbedColor.Success)] });
{ $set: { wordlistEnabled: true } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(
`### Word filter enabled!\nThere are currently ${config?.wordlist?.length ?? 0} words on your list.`,
null,
EmbedColor.Success
),
] });
break; break;
} }
case 'disable': { case "disable": {
await dbs.SERVERS.update( await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $set: { wordlistEnabled: false } }, { upsert: true });
{ id: message.channel!.serverId! }, await message.reply({ embeds: [embed("Word filter disabled.", null, EmbedColor.SoftError)] });
{ $set: { wordlistEnabled: false } },
{ upsert: true },
);
await message.reply({ embeds: [
embed('Word filter disabled.', null, EmbedColor.SoftError),
] });
break; break;
} }
case 'add': { case "add": {
let strictness: any = 'HARD'; let strictness: any = "HARD";
if (['soft', 'hard', 'strict'].includes(args[0].toLowerCase())) { if (["soft", "hard", "strict"].includes(args[0].toLowerCase())) {
strictness = args.shift()!.toUpperCase() as any; strictness = args.shift()!.toUpperCase() as any;
} }
const word = args.join(' ').toLowerCase(); const word = args.join(" ").toLowerCase();
if (!word) return message.reply('You didn\'t provide a word to add to the list!'); if (!word) return message.reply("You didn't provide a word to add to the list!");
if (config?.wordlist?.find(w => w.word == word)) return await message.reply('That word is already on the list!'); if (config?.wordlist?.find((w) => w.word == word)) return await message.reply("That word is already on the list!");
await dbs.SERVERS.update( await dbs.SERVERS.update({ id: message.channel!.serverId! }, { $push: { wordlist: { strictness, word } } }, { upsert: true });
{ id: message.channel!.serverId! }, await message.reply({ embeds: [embed(`Word added with strictness **${strictness}**.`, null, EmbedColor.Success)] });
{ $push: { wordlist: { strictness, word } } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(`Word added with strictness **${strictness}**.`, null, EmbedColor.Success),
] });
break; break;
} }
case 'remove': { case "remove": {
const word = args.join(' ').toLowerCase(); const word = args.join(" ").toLowerCase();
if (!word) return message.reply('You need to provide the word to remove from the list.'); if (!word) return message.reply("You need to provide the word to remove from the list.");
if (!config?.wordlist?.find(w => w.word == word)) return await message.reply('That word is not on the list.'); 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! }, { $pull: { wordlist: { word } } }, { upsert: true });
{ id: message.channel!.serverId! }, await message.reply({ embeds: [embed(`Word removed.`, null, EmbedColor.Success)] });
{ $pull: { wordlist: { word } } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(`Word removed.`, null, EmbedColor.Success),
] });
break; break;
} }
case 'show': { case "show": {
const formData = new FormData(); const formData = new FormData();
formData.append( formData.append(`wordlist_${message.channel?.serverId}`, config?.wordlist?.map((w) => `${w.strictness}\t${w.word}`).join("\n") ?? "", `wordlist_${message.channel?.serverId}.txt`);
`wordlist_${message.channel?.serverId}`,
config?.wordlist?.map(w => `${w.strictness}\t${w.word}`).join('\n') ?? '',
`wordlist_${message.channel?.serverId}.txt`
);
try { try {
const channel = await getDmChannel(message.authorId!); const channel = await getDmChannel(message.authorId!);
const res = await axios.post( const res = await axios.post(`${client.configuration?.features.autumn.url}/attachments`, formData, { headers: formData.getHeaders(), responseType: "json" });
`${client.configuration?.features.autumn.url}/attachments`,
formData,
{ headers: formData.getHeaders(), responseType: 'json' }
);
await channel.sendMessage({ await channel.sendMessage({
attachments: [(res.data as any).id], attachments: [(res.data as any).id],
embeds: [ embed( embeds: [embed(`Here's the current word list for **${message.channel?.server?.name}**.`, "Word List", EmbedColor.Success)],
`Here's the current word list for **${message.channel?.server?.name}**.`,
'Word List',
EmbedColor.Success
) ],
}); });
await message.reply({ embeds: [ await message.reply({ embeds: [embed(`I have sent the current word list to your direct messages!`, null, EmbedColor.Success)] });
embed(`I have sent the current word list to your direct messages!`, null, EmbedColor.Success),
] });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
break; break;
} }
case 'message': { case "message": {
const msg = args.join(' '); const msg = args.join(" ");
if (!msg) { if (!msg) {
return await message.reply({ embeds: [ return await message.reply({
embeds: [
embed( embed(
'This command lets you change the message the bot will send if a message is filtered.\n' + "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' + "Note that this message will not be sent if the configured action is to log events only.\n" +
'The current message is:\n' + "The current message is:\n" +
`>${sanitizeMessageContent(config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE).trim().replace(/\n/g, '\n>')}\n` + `>${sanitizeMessageContent(config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE)
'`{{user_id}}` will be substituted for the target user\'s ID.', .trim()
'Warning message', .replace(/\n/g, "\n>")}\n` +
EmbedColor.Success "`{{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)] });
{ $set: { wordlistAction: { action: config?.wordlistAction?.action ?? 'LOG', message: msg } } },
{ upsert: true },
);
await message.reply({ embeds: [
embed(
'Filter message set!',
null,
EmbedColor.Success
),
] });
break; break;
} }
case 'action': { case "action": {
let action: string; let action: string;
switch (args[0]?.toLowerCase()) { switch (args[0]?.toLowerCase()) {
case 'log': case "log":
case 'delete': case "delete":
case 'warn': case "warn":
action = args[0].toUpperCase(); action = args[0].toUpperCase();
break; break;
default: default:
await message.reply({ embeds: [ await message.reply({
embeds: [
embed( embed(
'Please provide one of the following arguments:\n' + "Please provide one of the following arguments:\n" +
'- **log** (Log the message in mod action log channel)\n' + "- **log** (Log the message in mod action log channel)\n" +
'- **delete** (Log and delete the message)\n' + "- **delete** (Log and delete the message)\n" +
'- **warn** (Log and delete message, warn user)\n\n' + "- **warn** (Log and delete message, warn user)\n\n" +
`The currently configured action is **${config?.wordlistAction?.action ?? 'LOG'}**.`, `The currently configured action is **${config?.wordlistAction?.action ?? "LOG"}**.`,
null, null,
EmbedColor.SoftError EmbedColor.SoftError,
), ),
] }); ],
});
return; return;
} }
await dbs.SERVERS.update( await dbs.SERVERS.update(
{ id: message.channel!.serverId! }, { id: message.channel!.serverId! },
{ $set: { wordlistAction: { {
$set: {
wordlistAction: {
action: action as any, action: action as any,
message: config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE message: config?.wordlistAction?.message ?? WORDLIST_DEFAULT_MESSAGE,
} } }, },
},
},
{ upsert: true }, { upsert: true },
); );
await message.reply({ embeds: [ await message.reply({
embed( embeds: [embed(`Filter action set to **${action}**. ` + `Please make sure you configured a logging channel using **${DEFAULT_PREFIX}botctl logs**.`, null, EmbedColor.Success)],
`Filter action set to **${action}**. ` + });
`Please make sure you configured a logging channel using **${DEFAULT_PREFIX}botctl logs**.`,
null,
EmbedColor.Success
),
] });
break; break;
} }
case 'test': { case "test": {
const match = checkMessageForFilteredWords(args.join(' '), config as ServerConfig); const match = checkMessageForFilteredWords(args.join(" "), config as ServerConfig);
await message.reply({ embeds: [ await message.reply({
embeds: [
match match
? embed('Your word list matches this test phrase!', 'Filter Test', EmbedColor.SoftError) ? 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) : embed("Your word list does not match this test phrase!", "Filter Test", EmbedColor.Success),
] }); ],
});
break; break;
} }
default: { default: {
await message.reply({ embeds: [ await message.reply({
embeds: [
embed( embed(
`### This command allows you to configure a manual word filter.\n` + `### 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 enable** - Enable the word filter.\n` +
@ -320,18 +254,20 @@ export default {
`- **${DEFAULT_PREFIX}botctl filter action [log|delete|warn]** - Configure the action taken on filtered messages.\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` + `- **${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).`, `More documentation can be found [here](https://github.com/sussycatgirl/automod/wiki/Word-Filter).`,
'Word filter', "Word filter",
), ),
embed( embed(
`**Enabled:** ${!!config?.wordlistEnabled}` + (!config?.wordlistEnabled `**Enabled:** ${!!config?.wordlistEnabled}` +
? '' (!config?.wordlistEnabled
: `\n**Action:** ${config?.wordlistAction?.action ?? 'LOG'}\n` + ? ""
: `\n**Action:** ${config?.wordlistAction?.action ?? "LOG"}\n` +
`**Warning message:** ${config?.wordlistAction?.message}\n` + `**Warning message:** ${config?.wordlistAction?.message}\n` +
`**Wordlist length:** ${config?.wordlist?.length ?? 0}`), `**Wordlist length:** ${config?.wordlist?.length ?? 0}`),
'Current configuration', "Current configuration",
config?.wordlistEnabled ? EmbedColor.Success : EmbedColor.SoftError, config?.wordlistEnabled ? EmbedColor.Success : EmbedColor.SoftError,
), ),
] }); ],
});
break; break;
} }
} }
@ -339,21 +275,19 @@ export default {
} }
case undefined: case undefined:
case '': case "":
message.reply(`### Available subcommands\n` message.reply(
+ `- \`ignore_blacklist\` - Ignore the bot's global blacklist.\n` `### Available subcommands\n` + `- \`spam_detection\` - Toggle automatic spam detection.\n` + `- \`logs\` - Configure log channels.\n` + `- \`filter\` - Configure word filter.\n`,
+ `- \`spam_detection\` - Toggle automatic spam detection.\n` );
+ `- \`logs\` - Configure log channels.\n` break;
+ `- \`filter\` - Configure word filter.\n`);
break
default: default:
message.reply(`Unknown option`); message.reply(`Unknown option`);
} }
} catch (e) { } catch (e) {
console.error(''+e); console.error("" + e);
message.reply('Something went wrong: ' + e); message.reply("Something went wrong: " + e);
}
} }
},
} as SimpleCommand; } as SimpleCommand;
export { WORDLIST_DEFAULT_MESSAGE } export { WORDLIST_DEFAULT_MESSAGE };