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 | |
| 7 | export async function callback(_, member) { |
| 8 | try { await statsChannelRemove(_, member); } catch {} |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame^] | 9 | try { purgeByUser(member.id, member.guild); } catch {} // TODO: add this to ban as well |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | try { |
| 11 | const { log, NucleusColors, entry, renderUser, renderDelta } = member.client.logger |
| 12 | let data = { |
| 13 | meta: { |
| 14 | type: 'memberLeave', |
| 15 | displayName: 'Member Left', |
| 16 | calculateType: 'guildMemberUpdate', |
| 17 | color: NucleusColors.red, |
| 18 | emoji: "MEMBER" + (member.user.bot ? ".BOT" : "") + ".LEAVE", |
| 19 | timestamp: new Date().getTime() |
| 20 | }, |
| 21 | list: { |
| 22 | id: entry(member.id, `\`${member.id}\``), |
| 23 | name: entry(member.id, renderUser(member.user)), |
| 24 | joined: entry(member.joinedAt, renderDelta(member.joinedAt)), |
| 25 | left: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 26 | timeInServer: entry(new Date().getTime() - member.joinedAt, humanizeDuration(new Date().getTime() - member.joinedAt, { round: true })), |
| 27 | accountCreated: entry(member.user.createdAt, renderDelta(member.user.createdAt)), |
| 28 | serverMemberCount: member.guild.memberCount, |
| 29 | }, |
| 30 | hidden: { |
| 31 | guild: member.guild.id |
| 32 | } |
| 33 | } |
| 34 | log(data, member.client); |
| 35 | } catch {} |
| 36 | } |