blob: df212a2008842b25d81315a8d04e547e56676d8c [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import humanizeDuration from "humanize-duration";
2import getEmojiByName from "../utils/getEmojiByName.js";
pineafan32767212022-03-14 21:27:39 +00003
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "channelUpdate";
pineafan32767212022-03-14 21:27:39 +00005
6export async function callback(client, oc, nc) {
pineafan63fc5e22022-08-04 22:04:10 +01007 const config = await client.memory.readGuildInfo(nc.guild.id);
PineaFan538d3752023-01-12 21:48:23 +00008 return;
Skyler Grey11236ba2022-08-08 21:13:33 +01009 const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger;
pineafan32767212022-03-14 21:27:39 +000010
Skyler Grey75ea9172022-08-06 10:22:23 +010011 if (nc.parent && nc.parent.id === config.tickets.category) return;
pineafan32767212022-03-14 21:27:39 +000012
pineafan63fc5e22022-08-04 22:04:10 +010013 const auditLog = await getAuditLog(nc.guild, "CHANNEL_UPDATE");
Skyler Grey11236ba2022-08-08 21:13:33 +010014 const audit = auditLog.entries.filter((entry) => entry.target.id === nc.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010015 if (audit.executor.id === client.user.id) return;
pineafan32767212022-03-14 21:27:39 +000016
Skyler Grey75ea9172022-08-06 10:22:23 +010017 let emoji: string;
18 let readableType: string;
19 let displayName: string;
pineafan63fc5e22022-08-04 22:04:10 +010020 const changes = {
21 channelId: entry(nc.id, `\`${nc.id}\``),
22 channel: entry(nc.id, renderChannel(nc)),
23 edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
Skyler Grey11236ba2022-08-08 21:13:33 +010024 editedBy: entry(audit.executor.id, renderUser((await nc.guild.members.fetch(audit.executor.id)).user))
pineafan63fc5e22022-08-04 22:04:10 +010025 };
Skyler Grey11236ba2022-08-08 21:13:33 +010026 if (oc.name !== nc.name) changes.name = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010027 if (oc.position !== nc.position)
Skyler Grey11236ba2022-08-08 21:13:33 +010028 changes.position = entry([oc.position, nc.position], `${oc.position} -> ${nc.position}`);
pineafan63fc5e22022-08-04 22:04:10 +010029
30 switch (nc.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010031 case "GUILD_TEXT": {
32 emoji = "CHANNEL.TEXT.EDIT";
33 readableType = "Text";
34 displayName = "Text Channel";
35 let oldTopic = oc.topic,
36 newTopic = nc.topic;
37 if (oldTopic) {
38 if (oldTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +010039 oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +010040 else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
41 } else {
42 oldTopic = "None";
43 }
44 if (newTopic) {
45 if (newTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +010046 newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +010047 else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
48 } else {
49 newTopic = "None";
50 }
51 const nsfw = ["", ""];
Skyler Grey11236ba2022-08-08 21:13:33 +010052 nsfw[0] = oc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
53 nsfw[1] = nc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
Skyler Grey75ea9172022-08-06 10:22:23 +010054 if (oc.topic !== nc.topic)
Skyler Grey11236ba2022-08-08 21:13:33 +010055 changes.description = entry([oc.topic, nc.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
56 if (oc.nsfw !== nc.nsfw) changes.nsfw = entry([oc.nsfw, nc.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010057 if (oc.rateLimitPerUser !== nc.rateLimitPerUser)
58 changes.rateLimitPerUser = entry(
59 [oc.rateLimitPerUser, nc.rateLimitPerUser],
Skyler Grey11236ba2022-08-08 21:13:33 +010060 `${humanizeDuration(oc.rateLimitPerUser * 1000)} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
Skyler Grey75ea9172022-08-06 10:22:23 +010061 );
pineafan63fc5e22022-08-04 22:04:10 +010062
Skyler Grey75ea9172022-08-06 10:22:23 +010063 break;
64 }
65 case "GUILD_NEWS": {
66 emoji = "CHANNEL.TEXT.EDIT";
67 readableType = "News";
68 displayName = "News Channel";
69 let oldTopic = oc.topic,
70 newTopic = nc.topic;
71 if (oldTopic) {
72 if (oldTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +010073 oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +010074 else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
75 } else {
76 oldTopic = "None";
77 }
78 if (newTopic) {
79 if (newTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +010080 newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +010081 else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
82 } else {
83 newTopic = "None";
84 }
85 if (oc.nsfw !== nc.nsfw)
Skyler Grey11236ba2022-08-08 21:13:33 +010086 changes.nsfw = entry([oc.nsfw, nc.nsfw], `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010087 break;
88 }
89 case "GUILD_VOICE": {
90 emoji = "CHANNEL.VOICE.EDIT";
91 readableType = "Voice";
92 displayName = "Voice Channel";
93 if (oc.bitrate !== nc.bitrate)
Skyler Grey11236ba2022-08-08 21:13:33 +010094 changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010095 if (oc.userLimit !== nc.userLimit)
96 changes.maxUsers = entry(
97 [oc.userLimit, nc.userLimit],
Skyler Grey11236ba2022-08-08 21:13:33 +010098 `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
Skyler Grey75ea9172022-08-06 10:22:23 +010099 );
100 if (oc.rtcRegion !== nc.rtcRegion)
101 changes.region = entry(
102 [oc.rtcRegion, nc.rtcRegion],
Skyler Grey11236ba2022-08-08 21:13:33 +0100103 `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100104 );
105 break;
106 }
107 case "GUILD_STAGE": {
108 emoji = "CHANNEL.VOICE.EDIT";
109 readableType = "Stage";
110 displayName = "Stage Channel";
111 let oldTopic = oc.topic,
112 newTopic = nc.topic;
113 if (oldTopic) {
114 if (oldTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +0100115 oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
117 } else {
118 oldTopic = "None";
119 }
120 if (newTopic) {
121 if (newTopic.length > 256)
Skyler Grey11236ba2022-08-08 21:13:33 +0100122 newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
124 } else {
125 newTopic = "None";
126 }
127 if (oc.bitrate !== nc.bitrate)
Skyler Grey11236ba2022-08-08 21:13:33 +0100128 changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
Skyler Grey75ea9172022-08-06 10:22:23 +0100129 if (oc.userLimit !== nc.userLimit)
130 changes.maxUsers = entry(
131 [oc.userLimit, nc.userLimit],
Skyler Grey11236ba2022-08-08 21:13:33 +0100132 `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100133 );
134 if (oc.rtcRegion !== nc.rtcRegion)
135 changes.region = entry(
136 [oc.rtcRegion, nc.rtcRegion],
Skyler Grey11236ba2022-08-08 21:13:33 +0100137 `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
Skyler Grey75ea9172022-08-06 10:22:23 +0100138 );
139 break;
140 }
141 case "GUILD_CATEGORY": {
142 emoji = "CHANNEL.CATEGORY.EDIT";
143 readableType = "Category";
144 displayName = "Category";
145 break;
146 }
147 default: {
148 emoji = "CHANNEL.TEXT.EDIT";
149 readableType = "Channel";
150 displayName = "Channel";
151 }
pineafan63fc5e22022-08-04 22:04:10 +0100152 }
153 const t = oc.type.split("_")[1];
Skyler Grey75ea9172022-08-06 10:22:23 +0100154 if (oc.type !== nc.type)
Skyler Grey11236ba2022-08-08 21:13:33 +0100155 changes.type = entry([oc.type, nc.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
pineafan63fc5e22022-08-04 22:04:10 +0100156 if (!(Object.values(changes).length - 4)) return;
157 const data = {
Skyler Grey75ea9172022-08-06 10:22:23 +0100158 meta: {
pineafan63fc5e22022-08-04 22:04:10 +0100159 type: "channelUpdate",
160 displayName: displayName + " Edited",
161 calculateType: "channelUpdate",
162 color: NucleusColors.yellow,
163 emoji: emoji,
164 timestamp: audit.createdTimestamp
165 },
166 list: changes,
167 hidden: {
168 guild: nc.guild.id
pineafane625d782022-05-09 18:04:32 +0100169 }
pineafan63fc5e22022-08-04 22:04:10 +0100170 };
171 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +0100172}