blob: 17c45958d21f4edca07a8b299e88a4ab8b4f042b [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { purgeByUser } from "../actions/tickets/delete.js";
2import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
pineafane625d782022-05-09 18:04:32 +01003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "guildBanAdd";
pineafane625d782022-05-09 18:04:32 +01005
6export async function callback(client, ban) {
pineafan63fc5e22022-08-04 22:04:10 +01007 await statsChannelRemove(client, ban.user);
8 purgeByUser(ban.user.id, ban.guild);
Skyler Grey11236ba2022-08-08 21:13:33 +01009 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
Skyler Grey11236ba2022-08-08 21:13:33 +010011 const audit = auditLog.entries.filter((entry) => entry.target.id === ban.user.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010012 if (audit.executor.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010013 await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason);
pineafan63fc5e22022-08-04 22:04:10 +010014 const data = {
15 meta: {
16 type: "memberBan",
17 displayName: "Member Banned",
18 calculateType: "guildMemberPunish",
19 color: NucleusColors.red,
20 emoji: "PUNISH.BAN.RED",
21 timestamp: new Date().getTime()
22 },
23 list: {
24 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
25 name: entry(ban.user.id, renderUser(ban.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +010026 banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafan63fc5e22022-08-04 22:04:10 +010027 bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
29 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
pineafan63fc5e22022-08-04 22:04:10 +010030 serverMemberCount: ban.guild.memberCount
31 },
32 hidden: {
33 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010034 }
pineafan63fc5e22022-08-04 22:04:10 +010035 };
36 log(data);
pineafane625d782022-05-09 18:04:32 +010037}