Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 1 | import type { GuildAuditLogsEntry, GuildBan } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 2 | import { purgeByUser } from "../actions/tickets/delete.js"; |
| 3 | import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js"; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 4 | // @ts-expect-error |
| 5 | import type { HaikuClient } from "jshaiku"; |
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 | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 9 | export async function callback(client: HaikuClient, ban: GuildBan) { |
| 10 | await statsChannelRemove(client, undefined, ban.guild, ban.user); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | purgeByUser(ban.user.id, ban.guild); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 12 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD"); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 14 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | if (audit.executor.id === client.user.id) return; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 16 | await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | const data = { |
| 18 | meta: { |
| 19 | type: "memberBan", |
| 20 | displayName: "Member Banned", |
| 21 | calculateType: "guildMemberPunish", |
| 22 | color: NucleusColors.red, |
| 23 | emoji: "PUNISH.BAN.RED", |
| 24 | timestamp: new Date().getTime() |
| 25 | }, |
| 26 | list: { |
| 27 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
| 28 | name: entry(ban.user.id, renderUser(ban.user)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 29 | banned: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | bannedBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 31 | reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"), |
| 32 | accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 33 | serverMemberCount: ban.guild.memberCount |
| 34 | }, |
| 35 | hidden: { |
| 36 | guild: ban.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 38 | }; |
| 39 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 40 | } |