blob: f9b427aafb60a7ff0f0d3f5d5757d8372fbc4abb [file] [log] [blame]
Skyler Greyf21323a2022-08-13 23:58:22 +01001import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01002import { purgeByUser } from "../actions/tickets/delete.js";
PineaFan752af462022-12-31 21:59:38 +00003import type { NucleusClient } from "../utils/client.js";
pineafane625d782022-05-09 18:04:32 +01004
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "guildBanRemove";
pineafane625d782022-05-09 18:04:32 +01006
PineaFan752af462022-12-31 21:59:38 +00007export async function callback(client: NucleusClient, ban: GuildBan) {
pineafan63fc5e22022-08-04 22:04:10 +01008 purgeByUser(ban.user.id, ban.guild);
pineafan0f5cc782022-08-12 21:55:42 +01009 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010010 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE");
pineafan0f5cc782022-08-12 21:55:42 +010011 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => 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("unban", ban.guild.id, ban.user, audit.executor, audit.reason);
pineafan63fc5e22022-08-04 22:04:10 +010014 const data = {
15 meta: {
16 type: "memberUnban",
17 displayName: "Member Unbanned",
18 calculateType: "guildMemberPunish",
19 color: NucleusColors.green,
20 emoji: "PUNISH.BAN.GREEN",
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 unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafan63fc5e22022-08-04 22:04:10 +010027 unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt))
pineafan63fc5e22022-08-04 22:04:10 +010029 },
30 hidden: {
31 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010032 }
pineafan63fc5e22022-08-04 22:04:10 +010033 };
34 log(data);
pineafane625d782022-05-09 18:04:32 +010035}