diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-12 20:27:37 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-12 20:27:37 -0400 |
commit | ba2d7b7db0a627234ed08de9d6bec8cb675404a7 (patch) | |
tree | 9ade9ed549b52eac3f2966a5cee5478267eca7c4 /src/listeners/message | |
parent | cac6abf3efd563b83f8f0ce70ce4bcfa5ada1a27 (diff) | |
download | tanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.tar.gz tanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.tar.bz2 tanzanite-ba2d7b7db0a627234ed08de9d6bec8cb675404a7.zip |
revamp automod, refactoring, fixes
Diffstat (limited to 'src/listeners/message')
-rw-r--r-- | src/listeners/message/automodCreate.ts | 113 | ||||
-rw-r--r-- | src/listeners/message/automodUpdate.ts | 4 |
2 files changed, 5 insertions, 112 deletions
diff --git a/src/listeners/message/automodCreate.ts b/src/listeners/message/automodCreate.ts index 01fc803..3e98117 100644 --- a/src/listeners/message/automodCreate.ts +++ b/src/listeners/message/automodCreate.ts @@ -1,11 +1,5 @@ -import { BushListener, BushMessage } from '@lib'; -// @ts-expect-error: ts doesn't recognize json5 -import _badLinks from '@root/lib/badlinks'; // partially uses https://github.com/nacrt/SkyblockClient-REPO/blob/main/files/scamlinks.json -// @ts-expect-error: ts doesn't recognize json5 -import _badLinksSecret from '@root/lib/badlinks-secret'; // shhhh -// @ts-expect-error: ts doesn't recognize json5 -import _badWords from '@root/lib/badwords'; -import { MessageEmbed } from 'discord.js'; +import { BushListener } from '@lib'; +import { AutoMod } from '../../lib/common/automod'; import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; export default class AutomodMessageCreateListener extends BushListener { @@ -18,107 +12,6 @@ export default class AutomodMessageCreateListener extends BushListener { } public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<unknown> { - return await AutomodMessageCreateListener.automod(message); - } - - public static async automod(message: BushMessage): Promise<unknown> { - if (message.channel.type === 'DM' || !message.guild) return; - if (!(await message.guild.hasFeature('automod'))) return; - - const customAutomodPhrases = (await message.guild.getSetting('autoModPhases')) ?? {}; - - const badLinks: { [key: string]: 0 | 1 | 2 | 3 } = {}; - let temp = _badLinks; - if (_badLinksSecret) temp = temp.concat(_badLinksSecret); - - temp.forEach((link: string) => { - badLinks[link] = 3; - }); - const badWords: { [key: string]: 0 | 1 | 2 | 3 } = _badWords; - - const wordMap = { ...badWords, ...badLinks, ...customAutomodPhrases }; - const wordKeys = Object.keys(wordMap); - const offences: { [key: string]: 0 | 1 | 2 | 3 } = {}; - - const cleanMessageContent = message.content?.toLowerCase().replace(/ /g, ''); - for (const word of wordKeys) { - const cleanWord = word.toLowerCase().replace(/ /g, ''); - - if (cleanMessageContent.includes(cleanWord)) { - if (cleanWord === 'whore' && !message.content?.toLowerCase().includes(cleanWord)) return; - if (!offences[word]) offences[word] = wordMap[word as keyof typeof wordMap]; - } - } - - if (!Object.keys(offences)?.length) return; - - const highestOffence = Object.values(offences).sort((a, b) => b - a)[0]; - - switch (highestOffence) { - case 0: { - void message.delete().catch(() => {}); - break; - } - case 1: { - void message.delete().catch(() => {}); - void message.member?.warn({ - moderator: message.guild.me!, - reason: '[AutoMod] blacklisted word' - }); - - break; - } - case 2: { - void message.delete().catch(() => {}); - void message.member?.mute({ - moderator: message.guild.me!, - reason: '[AutoMod] blacklisted word', - duration: 900_000 // 15 minutes - }); - break; - } - case 3: { - void message.delete().catch(() => {}); - void message.member?.mute({ - moderator: message.guild.me!, - reason: '[AutoMod] blacklisted word', - duration: 0 // perm - }); - break; - } - } - - void client.console.info( - 'autoMod', - `Severity <<${highestOffence}>> action performed on <<${message.author.tag}>> (<<${message.author.id}>>) in <<#${message.channel.name}>> in <<${message.guild.name}>>` - ); - - const color = - highestOffence === 0 - ? util.colors.lightGray - : highestOffence === 1 - ? util.colors.yellow - : highestOffence === 2 - ? util.colors.orange - : util.colors.red; - - const automodChannel = await message.guild.getLogChannel('automod'); - if (!automodChannel) return; - - if (automodChannel.permissionsFor(message.guild.me!.id)?.has(['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'])) - void automodChannel.send({ - embeds: [ - new MessageEmbed() - .setTitle(`[Severity ${highestOffence}] Automod Action Performed`) - .setDescription( - `**User:** ${message.author} (${message.author.tag})\n**Sent From**: <#${message.channel.id}> [Jump to context](${ - message.url - })\n**Blacklisted Words:** ${util.surroundArray(Object.keys(offences), '`').join(', ')}` - ) - .addField('Message Content', `${await util.codeblock(message.content, 1024)}`) - .setColor(color) - .setTimestamp() - ] - }); + return new AutoMod(message); } } diff --git a/src/listeners/message/automodUpdate.ts b/src/listeners/message/automodUpdate.ts index 9ef229e..86411b2 100644 --- a/src/listeners/message/automodUpdate.ts +++ b/src/listeners/message/automodUpdate.ts @@ -1,6 +1,6 @@ import { BushListener, BushMessage } from '@lib'; +import { AutoMod } from '../../lib/common/automod'; import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; -import AutomodMessageCreateListener from './automodCreate'; export default class AutomodMessageUpdateListener extends BushListener { public constructor() { @@ -13,6 +13,6 @@ export default class AutomodMessageUpdateListener extends BushListener { public override async exec(...[_, newMessage]: BushClientEvents['messageUpdate']): Promise<unknown> { const fullMessage = newMessage.partial ? await newMessage.fetch() : (newMessage as BushMessage); - return await AutomodMessageCreateListener.automod(fullMessage); + return new AutoMod(fullMessage); } } |