aboutsummaryrefslogtreecommitdiff
path: root/src/listeners/member-custom/massBan.ts
blob: 501902eb9716a992abbd947b3d00f5d89ccbe7a0 (plain)
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
import {
	BanResponse,
	banResponse,
	BotListener,
	colors,
	Emitter,
	emojis,
	overflowEmbed,
	TanzaniteEvent,
	type BotClientEvents
} from '#lib';

export default class MassBanListener extends BotListener {
	public constructor() {
		super(TanzaniteEvent.MassBan, {
			emitter: Emitter.Client,
			event: TanzaniteEvent.MassBan
		});
	}

	public async exec(...[moderator, guild, reason, results]: BotClientEvents[TanzaniteEvent.MassBan]) {
		const logChannel = await guild.getLogChannel('moderation');
		if (!logChannel) return;

		const success = (res: BanResponse): boolean => [banResponse.SUCCESS, banResponse.DM_ERROR].includes(res as any);

		const lines = results.map(
			(reason, user) => `${success(reason) ? emojis.success : emojis.error} ${user}${success(reason) ? '' : ` - ${reason}`}`
		);

		const embeds = overflowEmbed(
			{
				color: colors.DarkRed,
				title: 'Mass Ban',
				timestamp: new Date().toISOString(),
				fields: [
					{ name: '**Moderator**', value: `${moderator} (${moderator.user.tag})` },
					{ name: '**Reason**', value: `${reason ? reason : '[No Reason Provided]'}` }
				]
			},
			lines
		);

		return await logChannel.send({ embeds });
	}
}