pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import humanizeDuration from 'humanize-duration'; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 2 | import { purgeByUser } from '../automations/tickets/delete.js'; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 3 | import { callback as statsChannelRemove } from '../automations/statsChannelRemove.js'; |
| 4 | |
| 5 | export const event = 'guildMemberRemove' |
| 6 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | export async function callback(client, member) { |
| 8 | try { await statsChannelRemove(client, member); } catch {} |
| 9 | try { purgeByUser(member.id, member.guild); } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | try { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 11 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger |
| 12 | let auditLog = await getAuditLog(member.guild, 'MEMBER_KICK'); |
| 13 | let audit = auditLog.entries.filter(entry => entry.target.id == member.id).first(); |
| 14 | let type = "kick" |
| 15 | if (audit) { |
| 16 | if (audit.createdAt - 100 < new Date().getTime()) { |
| 17 | type = "leave" |
| 18 | } else if (audit.executor.id == client.user.id) return |
| 19 | } |
| 20 | let data |
| 21 | if (type == "kick") { |
| 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 | id: 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 | timeInServer: entry(new Date().getTime() - member.joinedAt, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })), |
| 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 { |
| 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 | id: 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 | timeInServer: entry(new Date().getTime() - member.joinedTimestamp, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })), |
| 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 | } |
| 70 | log(data, member.client); |
| 71 | } catch {} |
| 72 | } |