blob: dd723d3884287a4f5af8dd55eca62aa4eb384960 [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 Grey75ea9172022-08-06 10:22:23 +01009 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } =
10 ban.user.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
Skyler Grey75ea9172022-08-06 10:22:23 +010012 const audit = auditLog.entries
13 .filter((entry) => entry.target.id === ban.user.id)
14 .first();
pineafan63fc5e22022-08-04 22:04:10 +010015 if (audit.executor.id === client.user.id) return;
Skyler Grey75ea9172022-08-06 10:22:23 +010016 await client.database.history.create(
17 "ban",
18 ban.guild.id,
19 ban.user,
20 audit.executor,
21 audit.reason
22 );
pineafan63fc5e22022-08-04 22:04:10 +010023 const data = {
24 meta: {
25 type: "memberBan",
26 displayName: "Member Banned",
27 calculateType: "guildMemberPunish",
28 color: NucleusColors.red,
29 emoji: "PUNISH.BAN.RED",
30 timestamp: new Date().getTime()
31 },
32 list: {
33 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
34 name: entry(ban.user.id, renderUser(ban.user)),
Skyler Grey75ea9172022-08-06 10:22:23 +010035 banned: entry(
36 new Date().getTime(),
37 renderDelta(new Date().getTime())
38 ),
pineafan63fc5e22022-08-04 22:04:10 +010039 bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010040 reason: entry(
41 audit.reason,
42 audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"
43 ),
44 accountCreated: entry(
45 ban.user.createdAt,
46 renderDelta(ban.user.createdAt)
47 ),
pineafan63fc5e22022-08-04 22:04:10 +010048 serverMemberCount: ban.guild.memberCount
49 },
50 hidden: {
51 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010052 }
pineafan63fc5e22022-08-04 22:04:10 +010053 };
54 log(data);
pineafane625d782022-05-09 18:04:32 +010055}