Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 1 | import { GuildChannel, AuditLogEvent, ChannelType, TextChannel, VoiceChannel, StageChannel } from "discord.js"; |
| 2 | import type { GuildAuditLogsEntry } from "discord.js"; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 3 | //@ts-expect-error |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | import humanizeDuration from "humanize-duration"; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 5 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | import getEmojiByName from "../utils/getEmojiByName.js"; |
TheCodedProf | 7b985d8 | 2023-06-08 16:40:41 -0400 | [diff] [blame] | 7 | import client from "../utils/client.js"; |
PineaFan | 19dc9b8 | 2023-01-19 12:25:54 +0000 | [diff] [blame] | 8 | import { capitalize } from "../utils/generateKeyValueList.js"; |
| 9 | |
TheCodedProf | 7b985d8 | 2023-06-08 16:40:41 -0400 | [diff] [blame] | 10 | let entry = client.logger.entry; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 11 | |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 12 | const channelTypeEmoji: Record<number, string> = { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 13 | 0: "Text", // Text channel |
| 14 | 2: "Voice", // Voice channel |
| 15 | 5: "Announcement", // Announcement channel |
| 16 | 13: "Stage", // Stage channel |
| 17 | 15: "Forum", // Forum channel |
| 18 | 99: "Rules" // Rules channel |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 19 | }; |
| 20 | |
Skyler Grey | e641623 | 2023-06-14 14:04:01 +0200 | [diff] [blame] | 21 | // this eslint rule is invalid here, as the type definition is actually incorrect |
| 22 | // if you make it an interface due to the [key: string]: unknown line. Try it if you like :) |
| 23 | // eslint-disable-next-line @typescript-eslint/consistent-type-definitions |
TheCodedProf | 7b985d8 | 2023-06-08 16:40:41 -0400 | [diff] [blame] | 24 | type channelChanges = { |
TheCodedProf | b493b8a | 2023-01-18 21:11:00 -0500 | [diff] [blame] | 25 | channelId: ReturnType<typeof entry>; |
| 26 | channel: ReturnType<typeof entry>; |
| 27 | edited: ReturnType<typeof entry>; |
| 28 | editedBy: ReturnType<typeof entry>; |
| 29 | type?: ReturnType<typeof entry>; |
| 30 | name?: ReturnType<typeof entry>; |
| 31 | position?: ReturnType<typeof entry>; |
| 32 | description?: ReturnType<typeof entry>; |
| 33 | nsfw?: ReturnType<typeof entry>; |
| 34 | slowmode?: ReturnType<typeof entry>; |
| 35 | topic?: ReturnType<typeof entry>; |
| 36 | bitrate?: ReturnType<typeof entry>; |
| 37 | userLimit?: ReturnType<typeof entry>; |
TheCodedProf | b493b8a | 2023-01-18 21:11:00 -0500 | [diff] [blame] | 38 | parent?: ReturnType<typeof entry>; |
| 39 | permissionOverwrites?: ReturnType<typeof entry>; |
| 40 | region?: ReturnType<typeof entry>; |
| 41 | maxUsers?: ReturnType<typeof entry>; |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 42 | autoArchiveDuration?: ReturnType<typeof entry>; |
TheCodedProf | 7b985d8 | 2023-06-08 16:40:41 -0400 | [diff] [blame] | 43 | [key: string]: unknown; |
Skyler Grey | f96a337 | 2023-06-14 19:08:46 +0200 | [diff] [blame^] | 44 | }; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 45 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 46 | export const event = "channelUpdate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 47 | |
TheCodedProf | 7b985d8 | 2023-06-08 16:40:41 -0400 | [diff] [blame] | 48 | export async function callback(_client: NucleusClient, oldChannel: GuildChannel, newChannel: GuildChannel) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 49 | const { getAuditLog, log, isLogging, NucleusColors, renderDelta, renderUser, renderChannel } = client.logger; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 50 | if (!(await isLogging(newChannel.guild.id, "channelUpdate"))) return; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 51 | const config = await client.memory.readGuildInfo(newChannel.guild.id); |
TheCodedProf | b493b8a | 2023-01-18 21:11:00 -0500 | [diff] [blame] | 52 | entry = client.logger.entry; |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 53 | if (newChannel.parent && newChannel.parent.id === config.tickets.category) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 54 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 55 | const auditLog: null | GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate> = ( |
| 56 | await getAuditLog(newChannel.guild, AuditLogEvent.ChannelUpdate) |
| 57 | ).filter( |
| 58 | (entry: GuildAuditLogsEntry) => (entry.target as GuildChannel)!.id === newChannel.id |
| 59 | )[0] as GuildAuditLogsEntry<AuditLogEvent.ChannelUpdate> | null; |
PineaFan | c4d6c3f | 2023-01-19 12:17:25 +0000 | [diff] [blame] | 60 | if (!auditLog) return; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 61 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 62 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 63 | let emoji: string; |
| 64 | let readableType: string; |
| 65 | let displayName: string; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 66 | const changes: channelChanges = { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 67 | channelId: entry(newChannel.id, `\`${newChannel.id}\``), |
| 68 | channel: entry(newChannel.id, renderChannel(newChannel)), |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 69 | edited: entry(Date.now(), renderDelta(Date.now())), |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 70 | editedBy: entry( |
| 71 | auditLog.executor!.id, |
| 72 | renderUser((await newChannel.guild.members.fetch(auditLog.executor!.id)).user) |
| 73 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 74 | }; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 75 | if (oldChannel.name !== newChannel.name) |
| 76 | changes.name = entry([oldChannel.name, newChannel.name], `${oldChannel.name} -> ${newChannel.name}`); |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 77 | if (oldChannel.position !== newChannel.position) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 78 | changes.position = entry( |
| 79 | [oldChannel.position.toString(), newChannel.position.toString()], |
| 80 | `${oldChannel.position} -> ${newChannel.position}` |
| 81 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 83 | switch (newChannel.type) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 84 | case ChannelType.PrivateThread: |
| 85 | case ChannelType.PublicThread: { |
| 86 | return; |
| 87 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 88 | case ChannelType.GuildText: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 89 | emoji = "CHANNEL.TEXT.EDIT"; |
| 90 | readableType = "Text"; |
| 91 | displayName = "Text Channel"; |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 92 | let oldTopic = (oldChannel as TextChannel).topic ?? "*None*", |
| 93 | newTopic = (oldChannel as TextChannel).topic ?? "*None*"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 94 | if (oldTopic) { |
| 95 | if (oldTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 96 | oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``; |
| 98 | } else { |
| 99 | oldTopic = "None"; |
| 100 | } |
| 101 | if (newTopic) { |
| 102 | if (newTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 103 | newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 104 | else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``; |
| 105 | } else { |
| 106 | newTopic = "None"; |
| 107 | } |
| 108 | const nsfw = ["", ""]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 109 | nsfw[0] = (oldChannel as TextChannel).nsfw |
| 110 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 111 | : `${getEmojiByName("CONTROL.CROSS")} No`; |
| 112 | nsfw[1] = (newChannel as TextChannel).nsfw |
| 113 | ? `${getEmojiByName("CONTROL.TICK")} Yes` |
| 114 | : `${getEmojiByName("CONTROL.CROSS")} No`; |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 115 | if (oldTopic !== newTopic) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 116 | changes.description = entry( |
| 117 | [(oldChannel as TextChannel).topic ?? "", (newChannel as TextChannel).topic ?? ""], |
| 118 | `\nBefore: ${oldTopic}\nAfter: ${newTopic}` |
| 119 | ); |
| 120 | if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw) |
| 121 | changes.nsfw = entry( |
| 122 | [(oldChannel as TextChannel).nsfw ? "On" : "Off", (newChannel as TextChannel).nsfw ? "On" : "Off"], |
| 123 | `${nsfw[0]} -> ${nsfw[1]}` |
| 124 | ); |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 125 | if ((oldChannel as TextChannel).rateLimitPerUser !== (newChannel as TextChannel).rateLimitPerUser) |
| 126 | changes.slowmode = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 127 | [ |
| 128 | (oldChannel as TextChannel).rateLimitPerUser.toString(), |
| 129 | (newChannel as TextChannel).rateLimitPerUser.toString() |
| 130 | ], |
| 131 | `${humanizeDuration((oldChannel as TextChannel).rateLimitPerUser * 1000)} -> ${humanizeDuration( |
| 132 | (newChannel as TextChannel).rateLimitPerUser * 1000 |
| 133 | )}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 134 | ); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 135 | if ( |
| 136 | (oldChannel as TextChannel).defaultAutoArchiveDuration !== |
| 137 | (newChannel as TextChannel).defaultAutoArchiveDuration |
| 138 | ) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 139 | changes.autoArchiveDuration = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 140 | [ |
| 141 | ((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString(), |
| 142 | ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString() |
| 143 | ], |
| 144 | `${humanizeDuration( |
| 145 | ((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000 |
| 146 | )} -> ${humanizeDuration( |
| 147 | ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000 |
| 148 | )}` |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 149 | ); |
| 150 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 151 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 152 | break; |
| 153 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 154 | case ChannelType.GuildAnnouncement: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 155 | emoji = "CHANNEL.TEXT.EDIT"; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 156 | readableType = "Announcement"; |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 157 | displayName = "Announcement Channel"; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 158 | let oldTopic = (oldChannel as TextChannel).topic, |
| 159 | newTopic = (newChannel as TextChannel).topic; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 160 | if (oldTopic) { |
| 161 | if (oldTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 162 | oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 163 | else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``; |
| 164 | } else { |
| 165 | oldTopic = "None"; |
| 166 | } |
| 167 | if (newTopic) { |
| 168 | if (newTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 169 | newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 170 | else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``; |
| 171 | } else { |
| 172 | newTopic = "None"; |
| 173 | } |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 174 | if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 175 | changes.nsfw = entry( |
| 176 | [(oldChannel as TextChannel).nsfw ? "On" : "Off", (newChannel as TextChannel).nsfw ? "On" : "Off"], |
| 177 | `${(oldChannel as TextChannel).nsfw ? "On" : "Off"} -> ${ |
| 178 | (newChannel as TextChannel).nsfw ? "On" : "Off" |
| 179 | }` |
| 180 | ); |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 181 | } |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 182 | if ( |
| 183 | (oldChannel as TextChannel).defaultAutoArchiveDuration !== |
| 184 | (newChannel as TextChannel).defaultAutoArchiveDuration |
| 185 | ) { |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 186 | changes.autoArchiveDuration = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 187 | [ |
| 188 | ((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString(), |
| 189 | ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString() |
| 190 | ], |
| 191 | `${humanizeDuration( |
| 192 | ((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000 |
| 193 | )} -> ${humanizeDuration( |
| 194 | ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000 |
| 195 | )}` |
TheCodedProf | 6ec331b | 2023-02-20 12:13:06 -0500 | [diff] [blame] | 196 | ); |
| 197 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 198 | break; |
| 199 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 200 | case ChannelType.GuildVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 201 | emoji = "CHANNEL.VOICE.EDIT"; |
| 202 | readableType = "Voice"; |
| 203 | displayName = "Voice Channel"; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 204 | if ((oldChannel as VoiceChannel).bitrate !== (newChannel as VoiceChannel).bitrate) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 205 | changes.bitrate = entry( |
| 206 | [(oldChannel as VoiceChannel).bitrate.toString(), (newChannel as VoiceChannel).bitrate.toString()], |
| 207 | `${(oldChannel as VoiceChannel).bitrate} -> ${(newChannel as VoiceChannel).bitrate}` |
| 208 | ); |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 209 | if ((oldChannel as VoiceChannel).userLimit !== (newChannel as VoiceChannel).userLimit) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 210 | changes.maxUsers = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 211 | [ |
| 212 | (oldChannel as VoiceChannel).userLimit.toString(), |
| 213 | (newChannel as VoiceChannel).userLimit.toString() |
| 214 | ], |
| 215 | `${ |
| 216 | (oldChannel as VoiceChannel).userLimit ? (oldChannel as VoiceChannel).userLimit : "Unlimited" |
| 217 | } -> ${(newChannel as VoiceChannel).userLimit}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 218 | ); |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 219 | if ((oldChannel as VoiceChannel).rtcRegion !== (newChannel as VoiceChannel).rtcRegion) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 220 | changes.region = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 221 | [ |
| 222 | (oldChannel as VoiceChannel).rtcRegion ?? "automatic", |
| 223 | (newChannel as VoiceChannel).rtcRegion ?? "automatic" |
| 224 | ], |
| 225 | `${capitalize( |
| 226 | (oldChannel as VoiceChannel).rtcRegion?.toUpperCase() ?? "automatic" |
| 227 | )} -> ${capitalize((newChannel as VoiceChannel).rtcRegion?.toUpperCase() ?? "automatic")}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 228 | ); |
| 229 | break; |
| 230 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 231 | case ChannelType.GuildStageVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 232 | emoji = "CHANNEL.VOICE.EDIT"; |
| 233 | readableType = "Stage"; |
| 234 | displayName = "Stage Channel"; |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 235 | let oldTopic = (oldChannel as StageChannel).topic, |
| 236 | newTopic = (newChannel as StageChannel).topic; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 237 | if (oldTopic) { |
| 238 | if (oldTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 239 | oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 240 | else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``; |
| 241 | } else { |
| 242 | oldTopic = "None"; |
| 243 | } |
| 244 | if (newTopic) { |
| 245 | if (newTopic.length > 256) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 246 | newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 247 | else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``; |
| 248 | } else { |
| 249 | newTopic = "None"; |
| 250 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 251 | if ((oldChannel as StageChannel).bitrate !== (newChannel as StageChannel).bitrate) |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 252 | changes.bitrate = entry( |
| 253 | [(oldChannel as StageChannel).bitrate.toString(), (newChannel as StageChannel).bitrate.toString()], |
| 254 | `${(oldChannel as StageChannel).bitrate} -> ${(newChannel as StageChannel).bitrate}` |
| 255 | ); |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 256 | if ((oldChannel as StageChannel).userLimit !== (newChannel as StageChannel).userLimit) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 257 | changes.maxUsers = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 258 | [ |
| 259 | (oldChannel as StageChannel).userLimit.toString(), |
| 260 | (newChannel as StageChannel).userLimit.toString() |
| 261 | ], |
| 262 | `${ |
| 263 | (oldChannel as StageChannel).userLimit ? (oldChannel as StageChannel).userLimit : "Unlimited" |
| 264 | } -> ${(newChannel as StageChannel).userLimit}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 265 | ); |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 266 | if ((oldChannel as StageChannel).rtcRegion !== (newChannel as StageChannel).rtcRegion) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 267 | changes.region = entry( |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 268 | [ |
| 269 | (oldChannel as StageChannel).rtcRegion ?? "Automatic", |
| 270 | (newChannel as StageChannel).rtcRegion ?? "Automatic" |
| 271 | ], |
| 272 | `${capitalize( |
| 273 | (oldChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic" |
| 274 | )} -> ${capitalize((newChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic")}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 275 | ); |
| 276 | break; |
| 277 | } |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 278 | case ChannelType.GuildCategory: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 279 | emoji = "CHANNEL.CATEGORY.EDIT"; |
| 280 | readableType = "Category"; |
| 281 | displayName = "Category"; |
| 282 | break; |
| 283 | } |
| 284 | default: { |
| 285 | emoji = "CHANNEL.TEXT.EDIT"; |
| 286 | readableType = "Channel"; |
| 287 | displayName = "Channel"; |
| 288 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 289 | } |
PineaFan | 638eb13 | 2023-01-19 10:41:22 +0000 | [diff] [blame] | 290 | const ocType = channelTypeEmoji[oldChannel.type], |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 291 | ncType = channelTypeEmoji[newChannel.type]; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 292 | if (oldChannel.type !== newChannel.type) changes.type = entry([ocType!, ncType!], `${ocType!} -> ${readableType}`); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 293 | if (!(Object.values(changes).length - 4)) return; |
| 294 | const data = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 295 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 296 | type: "channelUpdate", |
| 297 | displayName: displayName + " Edited", |
| 298 | calculateType: "channelUpdate", |
| 299 | color: NucleusColors.yellow, |
| 300 | emoji: emoji, |
TheCodedProf | 309d618 | 2023-01-18 18:10:29 -0500 | [diff] [blame] | 301 | timestamp: auditLog.createdTimestamp |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 302 | }, |
| 303 | list: changes, |
| 304 | hidden: { |
PineaFan | e6ba788 | 2023-01-18 20:41:16 +0000 | [diff] [blame] | 305 | guild: newChannel.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 306 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 307 | }; |
Skyler Grey | f4f21c4 | 2023-03-08 14:36:29 +0000 | [diff] [blame] | 308 | await log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 309 | } |