PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 1 | import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js"; |
| 2 | import { AuditLogEvent } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import { purgeByUser } from "../actions/tickets/delete.js"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 4 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 5 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | export const event = "guildBanRemove"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 8 | export async function callback(client: NucleusClient, ban: GuildBan) { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 9 | purgeByUser(ban.user.id, ban.guild.id); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 10 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 11 | const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate)) |
| 12 | .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0]; |
| 13 | if (!auditLog) return; |
| 14 | if (auditLog.executor!.id === client.user!.id) return; |
| 15 | await client.database.history.create("unban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | const data = { |
| 17 | meta: { |
| 18 | type: "memberUnban", |
| 19 | displayName: "Member Unbanned", |
| 20 | calculateType: "guildMemberPunish", |
| 21 | color: NucleusColors.green, |
| 22 | emoji: "PUNISH.BAN.GREEN", |
| 23 | timestamp: new Date().getTime() |
| 24 | }, |
| 25 | list: { |
| 26 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
| 27 | name: entry(ban.user.id, renderUser(ban.user)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 28 | unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 29 | unbannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 30 | accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | }, |
| 32 | hidden: { |
| 33 | guild: ban.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 34 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 35 | }; |
| 36 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } |