blob: 5c7139a0ccb518f39db931d509680ba9d4ff3407 [file] [log] [blame]
pineafan377794f2022-04-18 19:01:01 +01001import getEmojiByName from "../utils/getEmojiByName.js";
2
pineafan32767212022-03-14 21:27:39 +00003export const event = 'channelDelete'
4
5export async function callback(client, channel) {
pineafane625d782022-05-09 18:04:32 +01006 try{
7 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger
pineafan32767212022-03-14 21:27:39 +00008
pineafane625d782022-05-09 18:04:32 +01009 let auditLog = await getAuditLog(channel.guild, 'CHANNEL_DELETE');
10 let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first();
11 if (audit.executor.id == client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000012
pineafane625d782022-05-09 18:04:32 +010013 let emoji;
14 let readableType;
15 let displayName;
16 switch (channel.type) {
17 case 'GUILD_TEXT': {
18 emoji = "CHANNEL.TEXT.DELETE";
19 readableType = "Text";
20 displayName = "Text Channel"
21 break;
22 }
23 case 'GUILD_VOICE': {
24 emoji = "CHANNEL.VOICE.DELETE";
25 readableType = "Voice";
26 displayName = "Voice Channel"
27 break;
28 }
29 case 'GUILD_CATEGORY': {
30 emoji = "CHANNEL.CATEGORY.DELETE";
31 readableType = "Category";
32 displayName = "Category"
33 break;
34 }
35 default: {
36 emoji = "CHANNEL.TEXT.DELETE";
37 readableType = "Channel";
38 displayName = "Channel"
39 }
40 }
41 let list = {
pineafanda6e5342022-07-03 10:03:16 +010042 channelIid: entry(channel.id, `\`${channel.id}\``),
pineafane625d782022-05-09 18:04:32 +010043 name: entry(channel.id, `${channel.name}`),
44 topic: null,
45 type: entry(channel.type, readableType),
46 category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"),
47 nsfw: null,
48 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)),
49 deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
50 deletedBy: entry(audit.executor.id, renderUser(audit.executor))
51 }
52 if (channel.topic != null ?? false) list.topic = entry(channel.topic, `\`\`\`\n${channel.topic.replace('`', "'")}\n\`\`\``);
53 else delete list.topic;
54 if (channel.nsfw !== null ?? false) list.nsfw = entry(channel.nsfw, channel.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`);
55 else delete list.nsfw;
pineafan32767212022-03-14 21:27:39 +000056
pineafane625d782022-05-09 18:04:32 +010057 let data = {
58 meta:{
59 type: 'channelDelete',
60 displayName: displayName + ' Deleted',
61 calculateType: 'channelUpdate',
62 color: NucleusColors.red,
63 emoji: emoji,
64 timestamp: audit.createdTimestamp
65 },
66 list: list,
67 hidden: {
68 guild: channel.guild.id
69 }
70 }
pineafan4edb7762022-06-26 19:21:04 +010071 log(data);
pineafane625d782022-05-09 18:04:32 +010072 } catch {}
pineafan32767212022-03-14 21:27:39 +000073}