blob: fc916ba93e95b447cd4eda42bfbd8425ee25d82b [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;
Skyler Greyda16adf2023-03-05 10:22:12 +00009 if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return;
10 const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanRemove)).filter(
11 (entry: GuildAuditLogsEntry) => (entry.target! as User).id === ban.user.id
12 )[0];
PineaFane6ba7882023-01-18 20:41:16 +000013 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",
TheCodedProf6ec331b2023-02-20 12:13:06 -050023 timestamp: Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010024 },
25 list: {
26 memberId: entry(ban.user.id, `\`${ban.user.id}\``),
27 name: entry(ban.user.id, renderUser(ban.user)),
TheCodedProf6ec331b2023-02-20 12:13:06 -050028 unbanned: entry(Date.now(), renderDelta(Date.now())),
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}