blob: 11661f7dc107a6f99174aaf201ced81f9462dcb3 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
2import { purgeByUser } from '../automations/tickets/delete.js';
3import { callback as statsChannelRemove } from '../automations/statsChannelRemove.js';
4
5export const event = 'guildBanRemove';
6
7export async function callback(client, ban) {
8 try { await statsChannelRemove(client, ban.user); } catch {}
9 try { purgeByUser(ban.user.id, ban.guild); } catch {}
10 try {
11 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger
12 let auditLog = await getAuditLog(ban.guild, 'MEMBER_BAN_REMOVE')
13 let audit = auditLog.entries.filter(entry => entry.target.id == ban.user.id).first();
14 if (audit.executor.id == client.user.id) return
15 let data = {
16 meta: {
17 type: 'memberUnban',
18 displayName: 'Member Unbanned',
19 calculateType: 'guildMemberPunish',
20 color: NucleusColors.green,
21 emoji: "PUNISH.BAN.GREEN",
22 timestamp: new Date().getTime()
23 },
24 list: {
25 id: entry(ban.user.id, `\`${ban.user.id}\``),
26 name: entry(ban.user.id, renderUser(ban.user)),
27 unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
28 unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
29 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
30 },
31 hidden: {
32 guild: ban.guild.id
33 }
34 }
35 log(data, ban.user.client);
36 } catch (e) {console.log(e)}
37}