blob: 3be4560e420c8f4f92ef29a12aa4b0a083e04a5f [file] [log] [blame]
PineaFane6ba7882023-01-18 20:41:16 +00001import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
2import { AuditLogEvent } from "discord.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) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05008 const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
9 if (!await isLogging(ban.guild.id, "guildMemberPunish")) return;
10 const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanRemove))
PineaFane6ba7882023-01-18 20:41:16 +000011 .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
12 if (!auditLog) return;
13 if (auditLog.executor!.id === client.user!.id) return;
14 await client.database.history.create("unban", ban.guild.id, ban.user, auditLog.executor, auditLog.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",
TheCodedProf6ec331b2023-02-20 12:13:06 -050022 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010023 },
24 list: {
25 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
26 name: entry(ban.user.id, renderUser(ban.user)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050027 unbanned: entry(Date.now(), renderDelta(Date.now())),
PineaFane6ba7882023-01-18 20:41:16 +000028 unbannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
29 accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp))
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}