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 | } |
Skyler Grey | c634e2b | 2022-08-06 17:50:48 +0100 | [diff] [blame^] | 43 | const list: { |
| 44 | channelId: string; |
| 45 | name: string; |
| 46 | topic?: string | null; |
| 47 | type: any; |
| 48 | category: any; |
| 49 | nsfw?: boolean | null; |
| 50 | created: any; |
| 51 | deleted: any; |
| 52 | deletedBy: any; |
| 53 | } = { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 54 | channelId: entry(channel.id, `\`${channel.id}\``), |
| 55 | name: entry(channel.id, `${channel.name}`), |
| 56 | topic: null, |
| 57 | type: entry(channel.type, readableType), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 58 | category: entry( |
| 59 | channel.parent ? channel.parent.id : null, |
| 60 | channel.parent ? channel.parent.name : "Uncategorised" |
| 61 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 62 | nsfw: null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 63 | created: entry( |
| 64 | channel.createdTimestamp, |
| 65 | renderDelta(channel.createdTimestamp) |
| 66 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 67 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 68 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)) |
| 69 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 70 | if (channel.topic !== null ?? false) |
| 71 | list.topic = entry( |
| 72 | channel.topic, |
| 73 | `\`\`\`\n${channel.topic.replace("`", "'")}\n\`\`\`` |
| 74 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 75 | else delete list.topic; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 76 | if (channel.nsfw !== null ?? false) |
| 77 | list.nsfw = entry( |
| 78 | channel.nsfw, |
| 79 | channel.nsfw |
| 80 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 81 | : `${getEmojiByName("CONTROL.CROSS")} No` |
| 82 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 83 | else delete list.nsfw; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 84 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 86 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 87 | type: "channelDelete", |
| 88 | displayName: displayName + " Deleted", |
| 89 | calculateType: "channelUpdate", |
| 90 | color: NucleusColors.red, |
| 91 | emoji: emoji, |
| 92 | timestamp: audit.createdTimestamp |
| 93 | }, |
| 94 | list: list, |
| 95 | hidden: { |
| 96 | guild: channel.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 97 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 98 | }; |
| 99 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 100 | } |