From 68ef45a7090a9b6d2b06426ebf754c782ea744c8 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 31 Dec 2021 11:30:50 -0500 Subject: add autoban I really hope I didn't screw this up --- src/listeners/bush/nameAutoBan.ts | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/listeners/bush/nameAutoBan.ts (limited to 'src/listeners/bush') diff --git a/src/listeners/bush/nameAutoBan.ts b/src/listeners/bush/nameAutoBan.ts new file mode 100644 index 0000000..dd702a5 --- /dev/null +++ b/src/listeners/bush/nameAutoBan.ts @@ -0,0 +1,62 @@ +import { AllowedMentions, BushListener, BushTextChannel, type BushClientEvents } from '#lib'; +import moment from 'moment'; + +export default class NameAutoBanListener extends BushListener { + public constructor() { + super('nameAutoBan', { + emitter: 'client', + event: 'guildMemberAdd', + category: 'guild' + }); + } + + 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') { + if (moment(member.user.createdAt).isBefore(moment().subtract(7, 'days'))) { + return client.console.warn( + 'nameAutoBan', + `<<${member.user.tag}>> has not been banned because their account is older than 7 days.` + ); + } + + 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 }) + } + } + ] + }); + + 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