diff options
Diffstat (limited to 'src/listeners/bush')
-rw-r--r-- | src/listeners/bush/joinAutoBan.ts (renamed from src/listeners/bush/nameAutoBan.ts) | 8 | ||||
-rw-r--r-- | src/listeners/bush/userUpdateAutoBan.ts | 62 |
2 files changed, 66 insertions, 4 deletions
diff --git a/src/listeners/bush/nameAutoBan.ts b/src/listeners/bush/joinAutoBan.ts index 0466ff0..97145a4 100644 --- a/src/listeners/bush/nameAutoBan.ts +++ b/src/listeners/bush/joinAutoBan.ts @@ -1,8 +1,8 @@ -import { AllowedMentions, BushListener, BushTextChannel, type BushClientEvents } from '#lib'; +import { AllowedMentions, BushListener, type BushClientEvents, type BushTextChannel } from '#lib'; -export default class NameAutoBanListener extends BushListener { +export default class JoinAutoBanListener extends BushListener { public constructor() { - super('nameAutoBan', { + super('joinAutoBan', { emitter: 'client', event: 'guildMemberAdd', category: 'bush' @@ -31,7 +31,7 @@ export default class NameAutoBanListener extends BushListener { .sendLogChannel('automod', { embeds: [ { - title: 'Name Auto Ban', + 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: { 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<void> { + 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)}.`; + + (<BushTextChannel>guild.channels.cache.find((c) => c.name === 'general')) + ?.send({ content, allowedMentions: AllowedMentions.none() }) + .catch(() => {}); + } + } +} |