blob: 5fd0b498a1be881591ce376aecf86d9e26c76b2e [file] [log] [blame]
Skyler Greyf21323a2022-08-13 23:58:22 +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";
PineaFan752af462022-12-31 21:59:38 +00004import type { NucleusClient } from "../utils/client.js";
pineafane625d782022-05-09 18:04:32 +01005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "guildBanAdd";
pineafane625d782022-05-09 18:04:32 +01007
PineaFan752af462022-12-31 21:59:38 +00008export async function callback(client: NucleusClient, ban: GuildBan) {
pineafan0f5cc782022-08-12 21:55:42 +01009 await statsChannelRemove(client, undefined, ban.guild, ban.user);
pineafan63fc5e22022-08-04 22:04:10 +010010 purgeByUser(ban.user.id, ban.guild);
pineafan0f5cc782022-08-12 21:55:42 +010011 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010012 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
pineafan0f5cc782022-08-12 21:55:42 +010013 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010014 if (audit.executor.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010015 await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason);
pineafan63fc5e22022-08-04 22:04:10 +010016 const data = {
17 meta: {
18 type: "memberBan",
19 displayName: "Member Banned",
20 calculateType: "guildMemberPunish",
21 color: NucleusColors.red,
22 emoji: "PUNISH.BAN.RED",
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 Grey11236ba2022-08-08 21:13:33 +010028 banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafan63fc5e22022-08-04 22:04:10 +010029 bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010030 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
31 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
pineafan63fc5e22022-08-04 22:04:10 +010032 serverMemberCount: ban.guild.memberCount
33 },
34 hidden: {
35 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010036 }
pineafan63fc5e22022-08-04 22:04:10 +010037 };
38 log(data);
pineafane625d782022-05-09 18:04:32 +010039}