blob: af55205c2d44bae7c0bc359c43f7663a60a6591c [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 }
43 const list = {
44 channelId: entry(channel.id, `\`${channel.id}\``),
45 name: entry(channel.id, `${channel.name}`),
46 topic: null,
47 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010048 category: entry(
49 channel.parent ? channel.parent.id : null,
50 channel.parent ? channel.parent.name : "Uncategorised"
51 ),
pineafan63fc5e22022-08-04 22:04:10 +010052 nsfw: null,
Skyler Grey75ea9172022-08-06 10:22:23 +010053 created: entry(
54 channel.createdTimestamp,
55 renderDelta(channel.createdTimestamp)
56 ),
pineafan63fc5e22022-08-04 22:04:10 +010057 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
58 deletedBy: entry(audit.executor.id, renderUser(audit.executor))
59 };
Skyler Grey75ea9172022-08-06 10:22:23 +010060 if (channel.topic !== null ?? false)
61 list.topic = entry(
62 channel.topic,
63 `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\``
64 );
pineafan63fc5e22022-08-04 22:04:10 +010065 else delete list.topic;
Skyler Grey75ea9172022-08-06 10:22:23 +010066 if (channel.nsfw !== null ?? false)
67 list.nsfw = entry(
68 channel.nsfw,
69 channel.nsfw
70 ? `${getEmojiByName("CONTROL.TICK")} Yes`
71 : `${getEmojiByName("CONTROL.CROSS")} No`
72 );
pineafan63fc5e22022-08-04 22:04:10 +010073 else delete list.nsfw;
pineafan32767212022-03-14 21:27:39 +000074
pineafan63fc5e22022-08-04 22:04:10 +010075 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +010076 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010077 type: "channelDelete",
78 displayName: displayName + " Deleted",
79 calculateType: "channelUpdate",
80 color: NucleusColors.red,
81 emoji: emoji,
82 timestamp: audit.createdTimestamp
83 },
84 list: list,
85 hidden: {
86 guild: channel.guild.id
pineafane625d782022-05-09 18:04:32 +010087 }
pineafan63fc5e22022-08-04 22:04:10 +010088 };
89 log(data);
pineafan32767212022-03-14 21:27:39 +000090}