blob: ee4620425218dfa56ecd8e9838700ec9ec30f18c [file] [log] [blame]
pineafan377794f2022-04-18 19:01:01 +01001import getEmojiByName from "../utils/getEmojiByName.js";
2
pineafan63fc5e22022-08-04 22:04:10 +01003export const event = "channelDelete";
pineafan32767212022-03-14 21:27:39 +00004
5export async function callback(client, channel) {
Skyler Grey75ea9172022-08-06 10:22:23 +01006 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } =
7 channel.client.logger;
pineafan32767212022-03-14 21:27:39 +00008
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE");
Skyler Grey75ea9172022-08-06 10:22:23 +010010 const audit = auditLog.entries
11 .filter((entry) => entry.target.id === channel.id)
12 .first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000014
pineafan63fc5e22022-08-04 22:04:10 +010015 let emoji;
16 let readableType;
17 let displayName;
18 switch (channel.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010019 case "GUILD_TEXT": {
20 emoji = "CHANNEL.TEXT.DELETE";
21 readableType = "Text";
22 displayName = "Text Channel";
23 break;
24 }
25 case "GUILD_VOICE": {
26 emoji = "CHANNEL.VOICE.DELETE";
27 readableType = "Voice";
28 displayName = "Voice Channel";
29 break;
30 }
31 case "GUILD_CATEGORY": {
32 emoji = "CHANNEL.CATEGORY.DELETE";
33 readableType = "Category";
34 displayName = "Category";
35 break;
36 }
37 default: {
38 emoji = "CHANNEL.TEXT.DELETE";
39 readableType = "Channel";
40 displayName = "Channel";
41 }
pineafan63fc5e22022-08-04 22:04:10 +010042 }
Skyler Greyc634e2b2022-08-06 17:50:48 +010043 const list: {
44 channelId: string;
45 name: string;
46 topic?: string | null;
47 type: any;
48 category: any;
49 nsfw?: boolean | null;
50 created: any;
51 deleted: any;
52 deletedBy: any;
53 } = {
pineafan63fc5e22022-08-04 22:04:10 +010054 channelId: entry(channel.id, `\`${channel.id}\``),
55 name: entry(channel.id, `${channel.name}`),
56 topic: null,
57 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010058 category: entry(
59 channel.parent ? channel.parent.id : null,
60 channel.parent ? channel.parent.name : "Uncategorised"
61 ),
pineafan63fc5e22022-08-04 22:04:10 +010062 nsfw: null,
Skyler Grey75ea9172022-08-06 10:22:23 +010063 created: entry(
64 channel.createdTimestamp,
65 renderDelta(channel.createdTimestamp)
66 ),
pineafan63fc5e22022-08-04 22:04:10 +010067 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
68 deletedBy: entry(audit.executor.id, renderUser(audit.executor))
69 };
Skyler Grey75ea9172022-08-06 10:22:23 +010070 if (channel.topic !== null ?? false)
71 list.topic = entry(
72 channel.topic,
73 `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``
74 );
pineafan63fc5e22022-08-04 22:04:10 +010075 else delete list.topic;
Skyler Grey75ea9172022-08-06 10:22:23 +010076 if (channel.nsfw !== null ?? false)
77 list.nsfw = entry(
78 channel.nsfw,
79 channel.nsfw
80 ? `${getEmojiByName("CONTROL.TICK")} Yes`
81 : `${getEmojiByName("CONTROL.CROSS")} No`
82 );
pineafan63fc5e22022-08-04 22:04:10 +010083 else delete list.nsfw;
pineafan32767212022-03-14 21:27:39 +000084
pineafan63fc5e22022-08-04 22:04:10 +010085 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010086 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010087 type: "channelDelete",
88 displayName: displayName + " Deleted",
89 calculateType: "channelUpdate",
90 color: NucleusColors.red,
91 emoji: emoji,
92 timestamp: audit.createdTimestamp
93 },
94 list: list,
95 hidden: {
96 guild: channel.guild.id
pineafane625d782022-05-09 18:04:32 +010097 }
pineafan63fc5e22022-08-04 22:04:10 +010098 };
99 log(data);
pineafan32767212022-03-14 21:27:39 +0000100}