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