blob: 22b7cd3b987eed0f21aaf335fdbc4c838abad6ca [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import humanizeDuration from 'humanize-duration';
pineafan377794f2022-04-18 19:01:01 +01002import { purgeByUser } from '../automations/tickets/delete.js';
pineafan32767212022-03-14 21:27:39 +00003import { callback as statsChannelRemove } from '../automations/statsChannelRemove.js';
4
5export const event = 'guildMemberRemove'
6
pineafane625d782022-05-09 18:04:32 +01007export async function callback(client, member) {
8 try { await statsChannelRemove(client, member); } catch {}
9 try { purgeByUser(member.id, member.guild); } catch {}
pineafan32767212022-03-14 21:27:39 +000010 try {
pineafane625d782022-05-09 18:04:32 +010011 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
12 let auditLog = await getAuditLog(member.guild, 'MEMBER_KICK');
13 let audit = auditLog.entries.filter(entry => entry.target.id == member.id).first();
14 let type = "kick"
15 if (audit) {
16 if (audit.createdAt - 100 < new Date().getTime()) {
17 type = "leave"
18 } else if (audit.executor.id == client.user.id) return
19 }
20 let data
21 if (type == "kick") {
22 data = {
23 meta: {
24 type: 'memberKick',
25 displayName: 'Member Kicked',
26 calculateType: 'guildMemberPunish',
27 color: NucleusColors.red,
28 emoji: "PUNISH.KICK.RED",
29 timestamp: new Date().getTime()
30 },
31 list: {
32 id: entry(member.id, `\`${member.id}\``),
33 name: entry(member.id, renderUser(member.user)),
34 joined: entry(member.joinedAt, renderDelta(member.joinedAt)),
35 kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
36 kickedBy: entry(audit.executor.id, renderUser(audit.executor)),
37 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
38 timeInServer: entry(new Date().getTime() - member.joinedAt, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })),
39 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
40 serverMemberCount: member.guild.memberCount,
41 },
42 hidden: {
43 guild: member.guild.id
44 }
45 }
46 } else {
47 data = {
48 meta: {
49 type: 'memberLeave',
50 displayName: 'Member Left',
51 calculateType: 'guildMemberUpdate',
52 color: NucleusColors.red,
53 emoji: "MEMBER." + (member.bot ? "BOT." : "") + "LEAVE",
54 timestamp: new Date().getTime()
55 },
56 list: {
57 id: entry(member.id, `\`${member.id}\``),
58 name: entry(member.id, renderUser(member.user)),
59 joined: entry(member.joinedTimestamp, renderDelta(member.joinedAt)),
60 left: entry(new Date().getTime(), renderDelta(new Date().getTime())),
61 timeInServer: entry(new Date().getTime() - member.joinedTimestamp, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })),
62 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
63 serverMemberCount: member.guild.memberCount,
64 },
65 hidden: {
66 guild: member.guild.id
67 }
pineafan32767212022-03-14 21:27:39 +000068 }
69 }
70 log(data, member.client);
71 } catch {}
72}