blob: cac4b4198807e5cac3f4910fd18b706d92e95c85 [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
2import { 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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050010 const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
pineafan0f5cc782022-08-12 21:55:42 +010011 await statsChannelRemove(client, undefined, ban.guild, ban.user);
PineaFane6ba7882023-01-18 20:41:16 +000012 purgeByUser(ban.user.id, ban.guild.id);
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050013 if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return;
14 const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanAdd))
PineaFane6ba7882023-01-18 20:41:16 +000015 .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
16 if (!auditLog) return;
17 if (auditLog.executor!.id === client.user!.id) return;
18 await client.database.history.create("ban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason);
pineafan63fc5e22022-08-04 22:04:10 +010019 const data = {
20 meta: {
21 type: "memberBan",
22 displayName: "Member Banned",
23 calculateType: "guildMemberPunish",
24 color: NucleusColors.red,
25 emoji: "PUNISH.BAN.RED",
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050026 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010027 },
28 list: {
29 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
30 name: entry(ban.user.id, renderUser(ban.user)),
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050031 banned: entry(Date.now(), renderDelta(Date.now())),
PineaFane6ba7882023-01-18 20:41:16 +000032 bannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
33 reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"),
34 accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)),
pineafan63fc5e22022-08-04 22:04:10 +010035 serverMemberCount: ban.guild.memberCount
36 },
37 hidden: {
38 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010039 }
pineafan63fc5e22022-08-04 22:04:10 +010040 };
41 log(data);
pineafane625d782022-05-09 18:04:32 +010042}