blob: a05389f3e81da266642b5156d58c399b6b4b1512 [file] [log] [blame]
pineafan0f5cc782022-08-12 21:55:42 +01001import type { GuildAuditLogsEntry, GuildBan } from 'discord.js';
pineafan63fc5e22022-08-04 22:04:10 +01002import { purgeByUser } from "../actions/tickets/delete.js";
3import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
pineafan0f5cc782022-08-12 21:55:42 +01004// @ts-expect-error
5import type { HaikuClient } from "jshaiku";
pineafane625d782022-05-09 18:04:32 +01006
pineafan63fc5e22022-08-04 22:04:10 +01007export const event = "guildBanAdd";
pineafane625d782022-05-09 18:04:32 +01008
pineafan0f5cc782022-08-12 21:55:42 +01009export async function callback(client: HaikuClient, ban: GuildBan) {
10 await statsChannelRemove(client, undefined, ban.guild, ban.user);
pineafan63fc5e22022-08-04 22:04:10 +010011 purgeByUser(ban.user.id, ban.guild);
pineafan0f5cc782022-08-12 21:55:42 +010012 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010013 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
pineafan0f5cc782022-08-12 21:55:42 +010014 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010015 if (audit.executor.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010016 await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason);
pineafan63fc5e22022-08-04 22:04:10 +010017 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 Grey11236ba2022-08-08 21:13:33 +010029 banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafan63fc5e22022-08-04 22:04:10 +010030 bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010031 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
32 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
pineafan63fc5e22022-08-04 22:04:10 +010033 serverMemberCount: ban.guild.memberCount
34 },
35 hidden: {
36 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010037 }
pineafan63fc5e22022-08-04 22:04:10 +010038 };
39 log(data);
pineafane625d782022-05-09 18:04:32 +010040}