blob: ac29238ecbc9ea2a3ba190f01ac4ae16d7d4ff5b [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) {
6 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger
7
8 let auditLog = await getAuditLog(channel.guild, 'CHANNEL_DELETE');
9 let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first();
10 if (audit.executor.id == client.user.id) return;
11
12 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 }
pineafan377794f2022-04-18 19:01:01 +010040 let list = {
41 id: 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
56 let 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 },
pineafan377794f2022-04-18 19:01:01 +010065 list: list,
pineafan32767212022-03-14 21:27:39 +000066 hidden: {
67 guild: channel.guild.id
68 }
69 }
70 log(data, channel.client);
71}