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"; |
| 4 | import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 5 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | export const event = "guildBanAdd"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 8 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 9 | export async function callback(client: NucleusClient, ban: GuildBan) { |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 10 | await statsChannelRemove(client, undefined, ban.guild, ban.user); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame^] | 11 | purgeByUser(ban.user.id, ban.guild.id); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 12 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame^] | 13 | const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate)) |
| 14 | .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0]; |
| 15 | if (!auditLog) return; |
| 16 | if (auditLog.executor!.id === client.user!.id) return; |
| 17 | await client.database.history.create("ban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | const data = { |
| 19 | meta: { |
| 20 | type: "memberBan", |
| 21 | displayName: "Member Banned", |
| 22 | calculateType: "guildMemberPunish", |
| 23 | color: NucleusColors.red, |
| 24 | emoji: "PUNISH.BAN.RED", |
| 25 | timestamp: new Date().getTime() |
| 26 | }, |
| 27 | list: { |
| 28 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
| 29 | name: entry(ban.user.id, renderUser(ban.user)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 30 | banned: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame^] | 31 | bannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 32 | reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"), |
| 33 | accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | serverMemberCount: ban.guild.memberCount |
| 35 | }, |
| 36 | hidden: { |
| 37 | guild: ban.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 38 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }; |
| 40 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 41 | } |