pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 2 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 3 | export const event = "channelDelete"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export async function callback(client, channel) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 6 | const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 7 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 8 | 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; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 11 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 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 | } |
| 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; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 55 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 56 | 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 68 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 69 | }; |
| 70 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 71 | } |