pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 1 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 2 | |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 3 | export const event = 'channelDelete' |
| 4 | |
| 5 | export async function callback(client, channel) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | try{ |
| 7 | const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 8 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 9 | 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; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 12 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 13 | 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 = { |
| 42 | id: entry(channel.id, `\`${channel.id}\``), |
| 43 | 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; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 56 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 57 | 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 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 71 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 72 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 73 | } |