blob: 842a48b16c8e61a9ab93fd73d188ed3bd62136d9 [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);
9 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger;
10 const auditLog = await getAuditLog(member.guild, "MEMBER_KICK");
11 const audit = auditLog.entries.filter(entry => entry.target.id === member.id).first();
12 let type = "leave";
13 if (audit) {
14 if (audit.executor.id === client.user.id) return;
15 if (audit.createdAt - 100 >= new Date().getTime()) {
16 type = "kick";
pineafane625d782022-05-09 18:04:32 +010017 }
pineafan63fc5e22022-08-04 22:04:10 +010018 }
19 let data;
20 if (type === "kick") {
21 await client.database.history.create("kick", member.guild.id, member.user, audit.executor, audit.reason);
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 memberId: 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 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
39 serverMemberCount: member.guild.memberCount
40 },
41 hidden: {
42 guild: member.guild.id
pineafane625d782022-05-09 18:04:32 +010043 }
pineafan63fc5e22022-08-04 22:04:10 +010044 };
45 } else {
46 await client.database.history.create("leave", member.guild.id, member.user, null, null);
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 memberId: 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 accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)),
62 serverMemberCount: member.guild.memberCount
63 },
64 hidden: {
65 guild: member.guild.id
pineafan32767212022-03-14 21:27:39 +000066 }
pineafan63fc5e22022-08-04 22:04:10 +010067 };
68 }
69 log(data);
pineafan32767212022-03-14 21:27:39 +000070}