blob: 5dff86f1a46d1ce720bb9e873e71ff9fd04167dc [file] [log] [blame]
pineafan73a7c4a2022-07-24 10:38:04 +01001import { purgeByUser } from '../actions/tickets/delete.js';
pineafan02ba0232022-07-24 22:16:15 +01002import { callback as statsChannelRemove } from '../reflex/statsChannelUpdate.js';
pineafan32767212022-03-14 21:27:39 +00003
4export const event = 'guildMemberRemove'
5
pineafane625d782022-05-09 18:04:32 +01006export async function callback(client, member) {
pineafane625d782022-05-09 18:04:32 +01007 try { purgeByUser(member.id, member.guild); } catch {}
pineafane23c4ec2022-07-27 21:56:27 +01008 try { await statsChannelRemove(client, member); } 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');
pineafane23c4ec2022-07-27 21:56:27 +010012 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
pineafane23c4ec2022-07-27 21:56:27 +010021 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.*"),
pineafane625d782022-05-09 18:04:32 +010039 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 {
pineafan4edb7762022-06-26 19:21:04 +010047 try { await client.database.history.create("leave", member.guild.id, member.user, null, null) } catch {}
pineafane625d782022-05-09 18:04:32 +010048 data = {
49 meta: {
50 type: 'memberLeave',
51 displayName: 'Member Left',
52 calculateType: 'guildMemberUpdate',
53 color: NucleusColors.red,
54 emoji: "MEMBER." + (member.bot ? "BOT." : "") + "LEAVE",
55 timestamp: new Date().getTime()
56 },
57 list: {
pineafanda6e5342022-07-03 10:03:16 +010058 memberId: entry(member.id, `\`${member.id}\``),
pineafane625d782022-05-09 18:04:32 +010059 name: entry(member.id, renderUser(member.user)),
60 joined: entry(member.joinedTimestamp, renderDelta(member.joinedAt)),
61 left: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafane625d782022-05-09 18:04:32 +010062 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 }
pineafan4edb7762022-06-26 19:21:04 +010070 log(data);
pineafan52906cd2022-06-29 22:02:36 +010071 } catch (e) { console.log(e) }
pineafan32767212022-03-14 21:27:39 +000072}