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) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 6 | const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = |
| 7 | channel.client.logger; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 8 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 10 | const audit = auditLog.entries |
| 11 | .filter((entry) => entry.target.id === channel.id) |
| 12 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | if (audit.executor.id === client.user.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 14 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | let emoji; |
| 16 | let readableType; |
| 17 | let displayName; |
| 18 | switch (channel.type) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 19 | 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 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 42 | } |
| 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | category: entry( |
| 49 | channel.parent ? channel.parent.id : null, |
| 50 | channel.parent ? channel.parent.name : "Uncategorised" |
| 51 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 52 | nsfw: null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 53 | created: entry( |
| 54 | channel.createdTimestamp, |
| 55 | renderDelta(channel.createdTimestamp) |
| 56 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 57 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 58 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)) |
| 59 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 60 | if (channel.topic !== null ?? false) |
| 61 | list.topic = entry( |
| 62 | channel.topic, |
| 63 | `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\`` |
| 64 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 65 | else delete list.topic; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 66 | 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 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 73 | else delete list.nsfw; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 74 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 75 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 76 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 77 | 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 87 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 88 | }; |
| 89 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 90 | } |