blob: c8a72a4dd69324a08bb779cf64f3d865dce68d4f [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) {
pineafan63fc5e22022-08-04 22:04:10 +01006 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger;
pineafan32767212022-03-14 21:27:39 +00007
pineafan63fc5e22022-08-04 22:04:10 +01008 const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE");
9 const audit = auditLog.entries.filter(entry => entry.target.id === channel.id).first();
10 if (audit.executor.id === client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000011
pineafan63fc5e22022-08-04 22:04:10 +010012 let emoji;
13 let readableType;
14 let displayName;
15 switch (channel.type) {
16 case "GUILD_TEXT": {
17 emoji = "CHANNEL.TEXT.DELETE";
18 readableType = "Text";
19 displayName = "Text Channel";
20 break;
21 }
22 case "GUILD_VOICE": {
23 emoji = "CHANNEL.VOICE.DELETE";
24 readableType = "Voice";
25 displayName = "Voice Channel";
26 break;
27 }
28 case "GUILD_CATEGORY": {
29 emoji = "CHANNEL.CATEGORY.DELETE";
30 readableType = "Category";
31 displayName = "Category";
32 break;
33 }
34 default: {
35 emoji = "CHANNEL.TEXT.DELETE";
36 readableType = "Channel";
37 displayName = "Channel";
38 }
39 }
40 const list = {
41 channelId: entry(channel.id, `\`${channel.id}\``),
42 name: entry(channel.id, `${channel.name}`),
43 topic: null,
44 type: entry(channel.type, readableType),
45 category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"),
46 nsfw: null,
47 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)),
48 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
49 deletedBy: entry(audit.executor.id, renderUser(audit.executor))
50 };
51 if (channel.topic !== null ?? false) list.topic = entry(channel.topic, `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``);
52 else delete list.topic;
53 if (channel.nsfw !== null ?? false) list.nsfw = entry(channel.nsfw, channel.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`);
54 else delete list.nsfw;
pineafan32767212022-03-14 21:27:39 +000055
pineafan63fc5e22022-08-04 22:04:10 +010056 const data = {
57 meta:{
58 type: "channelDelete",
59 displayName: displayName + " Deleted",
60 calculateType: "channelUpdate",
61 color: NucleusColors.red,
62 emoji: emoji,
63 timestamp: audit.createdTimestamp
64 },
65 list: list,
66 hidden: {
67 guild: channel.guild.id
pineafane625d782022-05-09 18:04:32 +010068 }
pineafan63fc5e22022-08-04 22:04:10 +010069 };
70 log(data);
pineafan32767212022-03-14 21:27:39 +000071}