blob: d095049df8a532b968f745e87cb9824ce9d03ae6 [file] [log] [blame]
pineafan73a7c4a2022-07-24 10:38:04 +01001import { purgeByUser } from '../actions/tickets/delete.js';
pineafan02ba0232022-07-24 22:16:15 +01002import { callback as statsChannelRemove } from '../reflex/statsChannelUpdate.js';
pineafane625d782022-05-09 18:04:32 +01003
4export const event = 'guildBanAdd';
5
6export async function callback(client, ban) {
7 try { await statsChannelRemove(client, ban.user); } catch {}
8 try { purgeByUser(ban.user.id, ban.guild); } catch {}
9 try {
10 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger
11 let auditLog = await getAuditLog(ban.guild, 'MEMBER_BAN_ADD')
12 let audit = auditLog.entries.filter(entry => entry.target.id == ban.user.id).first();
13 if (audit.executor.id == client.user.id) return
pineafan4edb7762022-06-26 19:21:04 +010014 try { await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason) } catch {}
pineafane625d782022-05-09 18:04:32 +010015 let data = {
16 meta: {
17 type: 'memberBan',
18 displayName: 'Member Banned',
19 calculateType: 'guildMemberPunish',
20 color: NucleusColors.red,
21 emoji: "PUNISH.BAN.RED",
22 timestamp: new Date().getTime()
23 },
24 list: {
pineafanda6e5342022-07-03 10:03:16 +010025 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
pineafane625d782022-05-09 18:04:32 +010026 name: entry(ban.user.id, renderUser(ban.user)),
27 banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
28 bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
29 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
30 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
31 serverMemberCount: ban.guild.memberCount,
32 },
33 hidden: {
34 guild: ban.guild.id
35 }
36 }
pineafan4edb7762022-06-26 19:21:04 +010037 log(data);
pineafane625d782022-05-09 18:04:32 +010038 } catch {}
39}