PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 1 | import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 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) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 10 | const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger; |
Skyler Grey | 5b78b42 | 2023-03-07 22:36:20 +0000 | [diff] [blame] | 11 | await statsChannelRemove(ban.user, ban.guild); |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 12 | await purgeByUser(ban.user.id, ban.guild.id); |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 13 | if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 14 | const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanAdd)).filter( |
| 15 | (entry: GuildAuditLogsEntry) => (entry.target! as User).id === ban.user.id |
| 16 | )[0]; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 17 | if (!auditLog) return; |
| 18 | if (auditLog.executor!.id === client.user!.id) return; |
| 19 | 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] | 20 | const data = { |
| 21 | meta: { |
| 22 | type: "memberBan", |
| 23 | displayName: "Member Banned", |
| 24 | calculateType: "guildMemberPunish", |
| 25 | color: NucleusColors.red, |
| 26 | emoji: "PUNISH.BAN.RED", |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 27 | timestamp: Date.now() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | }, |
| 29 | list: { |
| 30 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
| 31 | name: entry(ban.user.id, renderUser(ban.user)), |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 32 | banned: entry(Date.now(), renderDelta(Date.now())), |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 33 | bannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 34 | reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"), |
| 35 | accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 36 | serverMemberCount: ban.guild.memberCount |
| 37 | }, |
| 38 | hidden: { |
| 39 | guild: ban.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 40 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 41 | }; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 42 | await log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 43 | } |