blob: 5f1499d59162d10b4b6ee1e0e0b3165aa96b19cb [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";
pineafan0f5cc782022-08-12 21:55:42 +01003// @ts-expect-error
4import type { HaikuClient } from "jshaiku";
pineafane625d782022-05-09 18:04:32 +01005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "guildBanRemove";
pineafane625d782022-05-09 18:04:32 +01007
pineafan0f5cc782022-08-12 21:55:42 +01008export async function callback(client: HaikuClient, ban: GuildBan) {
pineafan63fc5e22022-08-04 22:04:10 +01009 purgeByUser(ban.user.id, ban.guild);
pineafan0f5cc782022-08-12 21:55:42 +010010 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010011 const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE");
pineafan0f5cc782022-08-12 21:55:42 +010012 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010014 await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason);
pineafan63fc5e22022-08-04 22:04:10 +010015 const data = {
16 meta: {
17 type: "memberUnban",
18 displayName: "Member Unbanned",
19 calculateType: "guildMemberPunish",
20 color: NucleusColors.green,
21 emoji: "PUNISH.BAN.GREEN",
22 timestamp: new Date().getTime()
23 },
24 list: {
25 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
26 name: entry(ban.user.id, renderUser(ban.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +010027 unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
pineafan63fc5e22022-08-04 22:04:10 +010028 unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010029 accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt))
pineafan63fc5e22022-08-04 22:04:10 +010030 },
31 hidden: {
32 guild: ban.guild.id
pineafane625d782022-05-09 18:04:32 +010033 }
pineafan63fc5e22022-08-04 22:04:10 +010034 };
35 log(data);
pineafane625d782022-05-09 18:04:32 +010036}