From 4b3e6b0ec2b03705479fb3338bfc62d82e28ffc8 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 1 Jan 2022 09:06:06 -0500 Subject: more automod --- src/listeners/bush/joinAutoBan.ts | 56 +++++++++++++++++++++++++++++ src/listeners/bush/nameAutoBan.ts | 56 ----------------------------- src/listeners/bush/userUpdateAutoBan.ts | 62 +++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 56 deletions(-) create mode 100644 src/listeners/bush/joinAutoBan.ts delete mode 100644 src/listeners/bush/nameAutoBan.ts create mode 100644 src/listeners/bush/userUpdateAutoBan.ts (limited to 'src/listeners/bush') diff --git a/src/listeners/bush/joinAutoBan.ts b/src/listeners/bush/joinAutoBan.ts new file mode 100644 index 0000000..97145a4 --- /dev/null +++ b/src/listeners/bush/joinAutoBan.ts @@ -0,0 +1,56 @@ +import { AllowedMentions, BushListener, type BushClientEvents, type BushTextChannel } from '#lib'; + +export default class JoinAutoBanListener extends BushListener { + public constructor() { + super('joinAutoBan', { + emitter: 'client', + event: 'guildMemberAdd', + category: 'bush' + }); + } + + public override async exec(...[member]: BushClientEvents['guildMemberAdd']): Promise { + if (!client.config.isProduction) return; + if (member.guild.id !== client.consts.mappings.guilds.bush) return; + const guild = member.guild; + + if (member.user.username === 'NotEnoughUpdates') { + const res = await member.bushBan({ + reason: "[AutoBan] 'NotEnoughUpdates' is a blacklisted name for this server.", + moderator: member.guild.me! + }); + + if (!['success', 'failed to dm'].includes(res)) { + return await guild.error( + 'nameAutoBan', + `Failed to autoban ${util.format.input(member.user.tag)} for 'NotEnoughUpdates', with error: ${util.format.input(res)}.` + ); + } + + await guild + .sendLogChannel('automod', { + embeds: [ + { + title: 'Name Auto Ban - User Join', + description: `**User:** ${member.user} (${member.user.tag})\n **Action:** Banned for using the blacklisted name 'NotEnoughUpdates'.`, + color: client.consts.colors.red, + author: { + name: member.user.tag, + iconURL: member.displayAvatarURL({ dynamic: true }) + } + } + ] + }) + .catch(() => {}); + + const content = + res === 'failed to dm' + ? `${util.emojis.warn} Banned ${util.format.input(member.user.tag)} however I could not send them a dm.` + : `${util.emojis.success} Successfully banned ${util.format.input(member.user.tag)}.`; + + (guild.channels.cache.find((c) => c.name === 'general')) + ?.send({ content, allowedMentions: AllowedMentions.none() }) + .catch(() => {}); + } + } +} diff --git a/src/listeners/bush/nameAutoBan.ts b/src/listeners/bush/nameAutoBan.ts deleted file mode 100644 index 0466ff0..0000000 --- a/src/listeners/bush/nameAutoBan.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { AllowedMentions, BushListener, BushTextChannel, type BushClientEvents } from '#lib'; - -export default class NameAutoBanListener extends BushListener { - public constructor() { - super('nameAutoBan', { - emitter: 'client', - event: 'guildMemberAdd', - category: 'bush' - }); - } - - public override async exec(...[member]: BushClientEvents['guildMemberAdd']): Promise { - if (!client.config.isProduction) return; - if (member.guild.id !== client.consts.mappings.guilds.bush) return; - const guild = member.guild; - - if (member.user.username === 'NotEnoughUpdates') { - const res = await member.bushBan({ - reason: "[AutoBan] 'NotEnoughUpdates' is a blacklisted name for this server.", - moderator: member.guild.me! - }); - - if (!['success', 'failed to dm'].includes(res)) { - return await guild.error( - 'nameAutoBan', - `Failed to autoban ${util.format.input(member.user.tag)} for 'NotEnoughUpdates', with error: ${util.format.input(res)}.` - ); - } - - await guild - .sendLogChannel('automod', { - embeds: [ - { - title: 'Name Auto Ban', - description: `**User:** ${member.user} (${member.user.tag})\n **Action:** Banned for using the blacklisted name 'NotEnoughUpdates'.`, - color: client.consts.colors.red, - author: { - name: member.user.tag, - iconURL: member.displayAvatarURL({ dynamic: true }) - } - } - ] - }) - .catch(() => {}); - - const content = - res === 'failed to dm' - ? `${util.emojis.warn} Banned ${util.format.input(member.user.tag)} however I could not send them a dm.` - : `${util.emojis.success} Successfully banned ${util.format.input(member.user.tag)}.`; - - (guild.channels.cache.find((c) => c.name === 'general')) - ?.send({ content, allowedMentions: AllowedMentions.none() }) - .catch(() => {}); - } - } -} diff --git a/src/listeners/bush/userUpdateAutoBan.ts b/src/listeners/bush/userUpdateAutoBan.ts new file mode 100644 index 0000000..c187eb2 --- /dev/null +++ b/src/listeners/bush/userUpdateAutoBan.ts @@ -0,0 +1,62 @@ +import { AllowedMentions, BushGuildMember, BushListener, type BushClientEvents, type BushTextChannel } from '#lib'; + +export default class UserUpdateAutoBanListener extends BushListener { + public constructor() { + super('userUpdateAutoBan', { + emitter: 'client', + event: 'userUpdate', + category: 'bush' + }); + } + + public override async exec(...[_oldUser, newUser]: BushClientEvents['userUpdate']): Promise { + if (!client.config.isProduction) return; + + if (newUser.username === 'NotEnoughUpdates') { + const member = await client.guilds.cache + .get(client.consts.mappings.guilds.bush) + ?.members.fetch(newUser.id) + .catch(() => undefined); + if (!member || !(member instanceof BushGuildMember)) return; + + const guild = member.guild; + + const res = await member.bushBan({ + reason: "[AutoBan] 'NotEnoughUpdates' is a blacklisted name for this server.", + moderator: member.guild.me! + }); + + if (!['success', 'failed to dm'].includes(res)) { + return await guild.error( + 'nameAutoBan', + `Failed to autoban ${util.format.input(member.user.tag)} for 'NotEnoughUpdates', with error: ${util.format.input(res)}.` + ); + } + + await guild + .sendLogChannel('automod', { + embeds: [ + { + title: 'Name Auto Ban - User Update', + description: `**User:** ${member.user} (${member.user.tag})\n **Action:** Banned for using the blacklisted name 'NotEnoughUpdates'.`, + color: client.consts.colors.red, + author: { + name: member.user.tag, + iconURL: member.displayAvatarURL({ dynamic: true }) + } + } + ] + }) + .catch(() => {}); + + const content = + res === 'failed to dm' + ? `${util.emojis.warn} Banned ${util.format.input(member.user.tag)} however I could not send them a dm.` + : `${util.emojis.success} Successfully banned ${util.format.input(member.user.tag)}.`; + + (guild.channels.cache.find((c) => c.name === 'general')) + ?.send({ content, allowedMentions: AllowedMentions.none() }) + .catch(() => {}); + } + } +} -- cgit