pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 1 | import { purgeByUser } from '../actions/tickets/delete.js'; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 2 | import { callback as statsChannelRemove } from '../reflex/statsChannelUpdate.js'; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 3 | |
| 4 | export const event = 'guildMemberRemove' |
| 5 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | export async function callback(client, member) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | try { purgeByUser(member.id, member.guild); } catch {} |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame^] | 8 | try { await statsChannelRemove(client, member); } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 9 | try { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 10 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger |
| 11 | let auditLog = await getAuditLog(member.guild, 'MEMBER_KICK'); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame^] | 12 | let audit = auditLog.entries.filter(entry => entry.target.id === member.id).first(); |
pineafan | 52906cd | 2022-06-29 22:02:36 +0100 | [diff] [blame] | 13 | let type = "leave" |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 14 | if (audit) { |
pineafan | 52906cd | 2022-06-29 22:02:36 +0100 | [diff] [blame] | 15 | if (audit.executor.id === client.user.id) return |
| 16 | if (audit.createdAt - 100 >= new Date().getTime()) { |
| 17 | type = "kick" |
| 18 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 19 | } |
| 20 | let data |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame^] | 21 | if (type === "kick") { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 22 | try { await client.database.history.create("kick", member.guild.id, member.user, audit.executor, audit.reason) } catch {} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 23 | 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: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 33 | memberId: entry(member.id, `\`${member.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 34 | 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.*"), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 39 | 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 { |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 47 | try { await client.database.history.create("leave", member.guild.id, member.user, null, null) } catch {} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 48 | 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: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 58 | memberId: entry(member.id, `\`${member.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 59 | 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())), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 62 | accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)), |
| 63 | serverMemberCount: member.guild.memberCount, |
| 64 | }, |
| 65 | hidden: { |
| 66 | guild: member.guild.id |
| 67 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 70 | log(data); |
pineafan | 52906cd | 2022-06-29 22:02:36 +0100 | [diff] [blame] | 71 | } catch (e) { console.log(e) } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 72 | } |