blob: bcb70d50c4623fb528fe9ddd479490e594bb52b7 [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
2import { AuditLogEvent } from "discord.js";
pineafan63fc5e22022-08-04 22:04:10 +01003import { purgeByUser } from "../actions/tickets/delete.js";
PineaFan752af462022-12-31 21:59:38 +00004import type { NucleusClient } from "../utils/client.js";
pineafane625d782022-05-09 18:04:32 +01005
pineafan63fc5e22022-08-04 22:04:10 +01006export const event = "guildBanRemove";
pineafane625d782022-05-09 18:04:32 +01007
PineaFan752af462022-12-31 21:59:38 +00008export async function callback(client: NucleusClient, ban: GuildBan) {
PineaFane6ba7882023-01-18 20:41:16 +00009 purgeByUser(ban.user.id, ban.guild.id);
pineafan0f5cc782022-08-12 21:55:42 +010010 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
PineaFane6ba7882023-01-18 20:41:16 +000011 const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
12 .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
13 if (!auditLog) return;
14 if (auditLog.executor!.id === client.user!.id) return;
15 await client.database.history.create("unban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason);
pineafan63fc5e22022-08-04 22:04:10 +010016 const data = {
17 meta: {
18 type: "memberUnban",
19 displayName: "Member Unbanned",
20 calculateType: "guildMemberPunish",
21 color: NucleusColors.green,
22 emoji: "PUNISH.BAN.GREEN",
23 timestamp: new Date().getTime()
24 },
25 list: {
26 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
27 name: entry(ban.user.id, renderUser(ban.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +010028 unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
PineaFane6ba7882023-01-18 20:41:16 +000029 unbannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
30 accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010031 },
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}