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 | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 3 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | export const event = "guildBanRemove"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 5 | |
| 6 | export async function callback(client, ban) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | await statsChannelRemove(client, ban.user); |
| 8 | purgeByUser(ban.user.id, ban.guild); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 9 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = |
| 10 | ban.user.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 12 | const audit = auditLog.entries |
| 13 | .filter((entry) => entry.target.id === ban.user.id) |
| 14 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | if (audit.executor.id === client.user.id) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 16 | await client.database.history.create( |
| 17 | "unban", |
| 18 | ban.guild.id, |
| 19 | ban.user, |
| 20 | audit.executor, |
| 21 | audit.reason |
| 22 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 23 | const data = { |
| 24 | meta: { |
| 25 | type: "memberUnban", |
| 26 | displayName: "Member Unbanned", |
| 27 | calculateType: "guildMemberPunish", |
| 28 | color: NucleusColors.green, |
| 29 | emoji: "PUNISH.BAN.GREEN", |
| 30 | timestamp: new Date().getTime() |
| 31 | }, |
| 32 | list: { |
| 33 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
| 34 | name: entry(ban.user.id, renderUser(ban.user)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | unbanned: entry( |
| 36 | new Date().getTime(), |
| 37 | renderDelta(new Date().getTime()) |
| 38 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | unbannedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 40 | accountCreated: entry( |
| 41 | ban.user.createdAt, |
| 42 | renderDelta(ban.user.createdAt) |
| 43 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | }, |
| 45 | hidden: { |
| 46 | guild: ban.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 47 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 48 | }; |
| 49 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 50 | } |