pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { purgeByUser } from "../actions/tickets/delete.js"; |
| 2 | import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 3 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | export const event = "guildMemberRemove"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | export async function callback(client, member) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | purgeByUser(member.id, member.guild); |
| 8 | await statsChannelRemove(client, member); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 9 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = |
| 10 | member.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | const auditLog = await getAuditLog(member.guild, "MEMBER_KICK"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 12 | const audit = auditLog.entries |
| 13 | .filter((entry) => entry.target.id === member.id) |
| 14 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | 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"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 20 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 21 | } |
| 22 | let data; |
| 23 | if (type === "kick") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 24 | await client.database.history.create( |
| 25 | "kick", |
| 26 | member.guild.id, |
| 27 | member.user, |
| 28 | audit.executor, |
| 29 | audit.reason |
| 30 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 44 | kicked: entry( |
| 45 | new Date().getTime(), |
| 46 | renderDelta(new Date().getTime()) |
| 47 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 48 | kickedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 49 | 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 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 59 | serverMemberCount: member.guild.memberCount |
| 60 | }, |
| 61 | hidden: { |
| 62 | guild: member.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 63 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 64 | }; |
| 65 | } else { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 66 | await client.database.history.create( |
| 67 | "leave", |
| 68 | member.guild.id, |
| 69 | member.user, |
| 70 | null, |
| 71 | null |
| 72 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 73 | 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 85 | 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 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 97 | serverMemberCount: member.guild.memberCount |
| 98 | }, |
| 99 | hidden: { |
| 100 | guild: member.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 101 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 102 | }; |
| 103 | } |
| 104 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 105 | } |