1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import { AllowedMentions, BotListener, colors, Emitter, emojis, format, mappings, type BotClientEvents } from '#lib';
import { Events, GuildMember, type TextChannel } from 'discord.js';
export default class UserUpdateAutoBanListener extends BotListener {
public constructor() {
super('userUpdateAutoBan', {
emitter: Emitter.Client,
event: Events.UserUpdate
});
}
public async exec(...[_oldUser, newUser]: BotClientEvents['userUpdate']): Promise<void> {
if (!this.client.config.isProduction) return;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const user = newUser;
const code = this.client.utils.getShared('autoBanCode');
if (!code) return;
if (eval(code)) {
const member = await this.client.guilds.cache
.get(mappings.guilds["Moulberry's Bush"])
?.members.fetch(newUser.id)
.catch(() => undefined);
if (!member || !(member instanceof GuildMember)) return;
const guild = member.guild;
const res = await member.customBan({
reason: '[AutoBan] Impersonation is not allowed.',
moderator: member.guild.members.me!
});
if (!['success', 'failed to dm'].includes(res)) {
return await guild.error(
'nameAutoBan',
`Failed to auto ban ${format.input(member.user.tag)} for blacklisted name, with error: ${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 blacklisted name.`,
color: colors.red,
author: {
name: member.user.tag,
icon_url: member.displayAvatarURL()
}
}
]
})
.catch(() => {});
const content =
res === 'failed to dm'
? `${emojis.warn} Banned ${format.input(member.user.tag)} however I could not send them a dm.`
: `${emojis.success} Successfully banned ${format.input(member.user.tag)}.`;
(<TextChannel>guild.channels.cache.find((c) => c.name === 'general'))
?.send({ content, allowedMentions: AllowedMentions.none() })
.catch(() => {});
}
}
}
|