blob: 85dc2afbf7e8cb179d02206c58ea77ec56660a1d [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
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}