blob: 4c2263d7016f23ef935d371919bc00ed3fc5bd16 [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 = "guildBanRemove";
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_REMOVE");
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 "unban",
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: "memberUnban",
26 displayName: "Member Unbanned",
27 calculateType: "guildMemberPunish",
28 color: NucleusColors.green,
29 emoji: "PUNISH.BAN.GREEN",
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 unbanned: entry(
36 new Date().getTime(),
37 renderDelta(new Date().getTime())
38 ),
pineafan63fc5e22022-08-04 22:04:10 +010039 unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010040 accountCreated: entry(
41 ban.user.createdAt,
42 renderDelta(ban.user.createdAt)
43 )
pineafan63fc5e22022-08-04 22:04:10 +010044 },
45 hidden: {
46 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010047 }
pineafan63fc5e22022-08-04 22:04:10 +010048 };
49 log(data);
pineafane625d782022-05-09 18:04:32 +010050}