blob: 3d962459bbb7581c8405fb5825867b7bffc00ebf [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
2import { AuditLogEvent } from 'discord.js';
pineafan63fc5e22022-08-04 22:04:10 +01003import { purgeByUser } from "../actions/tickets/delete.js";
4import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
PineaFan752af462022-12-31 21:59:38 +00005import type { NucleusClient } from "../utils/client.js";
pineafane625d782022-05-09 18:04:32 +01006
pineafan63fc5e22022-08-04 22:04:10 +01007export const event = "guildBanAdd";
pineafane625d782022-05-09 18:04:32 +01008
PineaFan752af462022-12-31 21:59:38 +00009export async function callback(client: NucleusClient, ban: GuildBan) {
pineafan0f5cc782022-08-12 21:55:42 +010010 await statsChannelRemove(client, undefined, ban.guild, ban.user);
PineaFane6ba7882023-01-18 20:41:16 +000011 purgeByUser(ban.user.id, ban.guild.id);
pineafan0f5cc782022-08-12 21:55:42 +010012 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
PineaFane6ba7882023-01-18 20:41:16 +000013 const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
14 .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
15 if (!auditLog) return;
16 if (auditLog.executor!.id === client.user!.id) return;
17 await client.database.history.create("ban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason);
pineafan63fc5e22022-08-04 22:04:10 +010018 const data = {
19 meta: {
20 type: "memberBan",
21 displayName: "Member Banned",
22 calculateType: "guildMemberPunish",
23 color: NucleusColors.red,
24 emoji: "PUNISH.BAN.RED",
25 timestamp: new Date().getTime()
26 },
27 list: {
28 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
29 name: entry(ban.user.id, renderUser(ban.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +010030 banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
PineaFane6ba7882023-01-18 20:41:16 +000031 bannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
32 reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"),
33 accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)),
pineafan63fc5e22022-08-04 22:04:10 +010034 serverMemberCount: ban.guild.memberCount
35 },
36 hidden: {
37 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010038 }
pineafan63fc5e22022-08-04 22:04:10 +010039 };
40 log(data);
pineafane625d782022-05-09 18:04:32 +010041}