blob: a6d1c14a8aa4ada8fb4110e61347980aaf9bf3b5 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import humanizeDuration from 'humanize-duration';
pineafan73a7c4a2022-07-24 10:38:04 +01002import { purgeByUser } from '../actions/tickets/delete.js';
3import { callback as statsChannelRemove } from '../reflex/statsChannelRemove.js';
pineafane625d782022-05-09 18:04:32 +01004
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
pineafan4edb7762022-06-26 19:21:04 +010015 try { await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason) } catch {}
pineafane625d782022-05-09 18:04:32 +010016 let data = {
17 meta: {
18 type: 'memberUnban',
19 displayName: 'Member Unbanned',
20 calculateType: 'guildMemberPunish',
21 color: NucleusColors.green,
22 emoji: "PUNISH.BAN.GREEN",
23 timestamp: new Date().getTime()
24 },
25 list: {
pineafanda6e5342022-07-03 10:03:16 +010026 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
pineafane625d782022-05-09 18:04:32 +010027 name: entry(ban.user.id, renderUser(ban.user)),
28 unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
29 unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
30 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
31 },
32 hidden: {
33 guild: ban.guild.id
34 }
35 }
pineafan4edb7762022-06-26 19:21:04 +010036 log(data);
pineafane625d782022-05-09 18:04:32 +010037 } catch (e) {console.log(e)}
38}