blob: d170396ab0d05f6ea4de6464a2999f40433b60fc [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { purgeByUser } from "../actions/tickets/delete.js";
2import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
pineafan32767212022-03-14 21:27:39 +00003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "guildMemberRemove";
pineafan32767212022-03-14 21:27:39 +00005
pineafane625d782022-05-09 18:04:32 +01006export async function callback(client, member) {
pineafan63fc5e22022-08-04 22:04:10 +01007 purgeByUser(member.id, member.guild);
8 await statsChannelRemove(client, member);
Skyler Grey75ea9172022-08-06 10:22:23 +01009 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
10 member.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(member.guild, "MEMBER_KICK");
Skyler Grey75ea9172022-08-06 10:22:23 +010012 const audit = auditLog.entries
13 .filter((entry) => entry.target.id === member.id)
14 .first();
pineafan63fc5e22022-08-04 22:04:10 +010015 let type = "leave";
16 if (audit) {
17 if (audit.executor.id === client.user.id) return;
18 if (audit.createdAt - 100 >= new Date().getTime()) {
19 type = "kick";
pineafane625d782022-05-09 18:04:32 +010020 }
pineafan63fc5e22022-08-04 22:04:10 +010021 }
22 let data;
23 if (type === "kick") {
Skyler Grey75ea9172022-08-06 10:22:23 +010024 await client.database.history.create(
25 "kick",
26 member.guild.id,
27 member.user,
28 audit.executor,
29 audit.reason
30 );
pineafan63fc5e22022-08-04 22:04:10 +010031 data = {
32 meta: {
33 type: "memberKick",
34 displayName: "Member Kicked",
35 calculateType: "guildMemberPunish",
36 color: NucleusColors.red,
37 emoji: "PUNISH.KICK.RED",
38 timestamp: new Date().getTime()
39 },
40 list: {
41 memberId: entry(member.id, `\`${member.id}\``),
42 name: entry(member.id, renderUser(member.user)),
43 joined: entry(member.joinedAt, renderDelta(member.joinedAt)),
Skyler Grey75ea9172022-08-06 10:22:23 +010044 kicked: entry(
45 new Date().getTime(),
46 renderDelta(new Date().getTime())
47 ),
pineafan63fc5e22022-08-04 22:04:10 +010048 kickedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010049 reason: entry(
50 audit.reason,
51 audit.reason
52 ? `\n> ${audit.reason}`
53 : "*No reason provided.*"
54 ),
55 accountCreated: entry(
56 member.user.createdAt,
57 renderDelta(member.user.createdAt)
58 ),
pineafan63fc5e22022-08-04 22:04:10 +010059 serverMemberCount: member.guild.memberCount
60 },
61 hidden: {
62 guild: member.guild.id
pineafane625d782022-05-09 18:04:32 +010063 }
pineafan63fc5e22022-08-04 22:04:10 +010064 };
65 } else {
Skyler Grey75ea9172022-08-06 10:22:23 +010066 await client.database.history.create(
67 "leave",
68 member.guild.id,
69 member.user,
70 null,
71 null
72 );
pineafan63fc5e22022-08-04 22:04:10 +010073 data = {
74 meta: {
75 type: "memberLeave",
76 displayName: "Member Left",
77 calculateType: "guildMemberUpdate",
78 color: NucleusColors.red,
79 emoji: "MEMBER." + (member.bot ? "BOT." : "") + "LEAVE",
80 timestamp: new Date().getTime()
81 },
82 list: {
83 memberId: entry(member.id, `\`${member.id}\``),
84 name: entry(member.id, renderUser(member.user)),
Skyler Grey75ea9172022-08-06 10:22:23 +010085 joined: entry(
86 member.joinedTimestamp,
87 renderDelta(member.joinedAt)
88 ),
89 left: entry(
90 new Date().getTime(),
91 renderDelta(new Date().getTime())
92 ),
93 accountCreated: entry(
94 member.user.createdAt,
95 renderDelta(member.user.createdAt)
96 ),
pineafan63fc5e22022-08-04 22:04:10 +010097 serverMemberCount: member.guild.memberCount
98 },
99 hidden: {
100 guild: member.guild.id
pineafan32767212022-03-14 21:27:39 +0000101 }
pineafan63fc5e22022-08-04 22:04:10 +0100102 };
103 }
104 log(data);
pineafan32767212022-03-14 21:27:39 +0000105}