blob: 122e01a7a71ea5a423913906a7a77ed5740ba169 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import humanizeDuration from 'humanize-duration';
pineafan73a7c4a2022-07-24 10:38:04 +01002import { purgeByUser } from '../actions/tickets/delete.js';
pineafan02ba0232022-07-24 22:16:15 +01003import { callback as statsChannelRemove } from '../reflex/statsChannelUpdate.js';
pineafan32767212022-03-14 21:27:39 +00004
5export const event = 'guildMemberRemove'
6
pineafane625d782022-05-09 18:04:32 +01007export async function callback(client, member) {
pineafane625d782022-05-09 18:04:32 +01008 try { purgeByUser(member.id, member.guild); } catch {}
pineafan32767212022-03-14 21:27:39 +00009 try {
pineafane625d782022-05-09 18:04:32 +010010 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger
11 let auditLog = await getAuditLog(member.guild, 'MEMBER_KICK');
12 let audit = auditLog.entries.filter(entry => entry.target.id == member.id).first();
pineafan52906cd2022-06-29 22:02:36 +010013 let type = "leave"
pineafane625d782022-05-09 18:04:32 +010014 if (audit) {
pineafan52906cd2022-06-29 22:02:36 +010015 if (audit.executor.id === client.user.id) return
16 if (audit.createdAt - 100 >= new Date().getTime()) {
17 type = "kick"
18 }
pineafane625d782022-05-09 18:04:32 +010019 }
20 let data
21 if (type == "kick") {
pineafan4edb7762022-06-26 19:21:04 +010022 try { await client.database.history.create("kick", member.guild.id, member.user, audit.executor, audit.reason) } catch {}
pineafane625d782022-05-09 18:04:32 +010023 data = {
24 meta: {
25 type: 'memberKick',
26 displayName: 'Member Kicked',
27 calculateType: 'guildMemberPunish',
28 color: NucleusColors.red,
29 emoji: "PUNISH.KICK.RED",
30 timestamp: new Date().getTime()
31 },
32 list: {
pineafanda6e5342022-07-03 10:03:16 +010033 memberId: entry(member.id, `\`${member.id}\``),
pineafane625d782022-05-09 18:04:32 +010034 name: entry(member.id, renderUser(member.user)),
35 joined: entry(member.joinedAt, renderDelta(member.joinedAt)),
36 kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
37 kickedBy: entry(audit.executor.id, renderUser(audit.executor)),
38 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
39 timeInServer: entry(new Date().getTime() - member.joinedAt, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })),
40 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
41 serverMemberCount: member.guild.memberCount,
42 },
43 hidden: {
44 guild: member.guild.id
45 }
46 }
47 } else {
pineafan4edb7762022-06-26 19:21:04 +010048 try { await client.database.history.create("leave", member.guild.id, member.user, null, null) } catch {}
pineafane625d782022-05-09 18:04:32 +010049 data = {
50 meta: {
51 type: 'memberLeave',
52 displayName: 'Member Left',
53 calculateType: 'guildMemberUpdate',
54 color: NucleusColors.red,
55 emoji: "MEMBER." + (member.bot ? "BOT." : "") + "LEAVE",
56 timestamp: new Date().getTime()
57 },
58 list: {
pineafanda6e5342022-07-03 10:03:16 +010059 memberId: entry(member.id, `\`${member.id}\``),
pineafane625d782022-05-09 18:04:32 +010060 name: entry(member.id, renderUser(member.user)),
61 joined: entry(member.joinedTimestamp, renderDelta(member.joinedAt)),
62 left: entry(new Date().getTime(), renderDelta(new Date().getTime())),
63 timeInServer: entry(new Date().getTime() - member.joinedTimestamp, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })),
64 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
65 serverMemberCount: member.guild.memberCount,
66 },
67 hidden: {
68 guild: member.guild.id
69 }
pineafan32767212022-03-14 21:27:39 +000070 }
71 }
pineafan4edb7762022-06-26 19:21:04 +010072 log(data);
pineafan52906cd2022-06-29 22:02:36 +010073 } catch (e) { console.log(e) }
pineafan02ba0232022-07-24 22:16:15 +010074 try { await statsChannelRemove(client, member); } catch {}
pineafan32767212022-03-14 21:27:39 +000075}