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); |
| 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"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 17 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 18 | } |
| 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 43 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 44 | }; |
| 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 |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 66 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 67 | }; |
| 68 | } |
| 69 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 70 | } |