blob: 6036ddf494afb4955aa4cd6ff94b26123cb0b4cb [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00002import { AuditLogEvent } from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01003import { purgeByUser } from "../actions/tickets/delete.js";
4import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
PineaFan752af462022-12-31 21:59:38 +00005import type { NucleusClient } from "../utils/client.js";
pineafane625d782022-05-09 18:04:32 +01006
pineafan63fc5e22022-08-04 22:04:10 +01007export const event = "guildBanAdd";
pineafane625d782022-05-09 18:04:32 +01008
PineaFan752af462022-12-31 21:59:38 +00009export async function callback(client: NucleusClient, ban: GuildBan) {
TheCodedProf6ec331b2023-02-20 12:13:06 -050010 const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
Skyler Grey5b78b422023-03-07 22:36:20 +000011 await statsChannelRemove(ban.user, ban.guild);
PineaFane6ba7882023-01-18 20:41:16 +000012 purgeByUser(ban.user.id, ban.guild.id);
TheCodedProf6ec331b2023-02-20 12:13:06 -050013 if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return;
Skyler Greyda16adf2023-03-05 10:22:12 +000014 const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanAdd)).filter(
15 (entry: GuildAuditLogsEntry) => (entry.target! as User).id === ban.user.id
16 )[0];
PineaFane6ba7882023-01-18 20:41:16 +000017 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);
pineafan63fc5e22022-08-04 22:04:10 +010020 const data = {
21 meta: {
22 type: "memberBan",
23 displayName: "Member Banned",
24 calculateType: "guildMemberPunish",
25 color: NucleusColors.red,
26 emoji: "PUNISH.BAN.RED",
TheCodedProf6ec331b2023-02-20 12:13:06 -050027 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010028 },
29 list: {
30 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
31 name: entry(ban.user.id, renderUser(ban.user)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050032 banned: entry(Date.now(), renderDelta(Date.now())),
PineaFane6ba7882023-01-18 20:41:16 +000033 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)),
pineafan63fc5e22022-08-04 22:04:10 +010036 serverMemberCount: ban.guild.memberCount
37 },
38 hidden: {
39 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010040 }
pineafan63fc5e22022-08-04 22:04:10 +010041 };
42 log(data);
pineafane625d782022-05-09 18:04:32 +010043}