-
Notifications
You must be signed in to change notification settings - Fork 13
/
update.js
315 lines (312 loc) · 9.78 KB
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import {
AttachmentBuilder,
GuildDefaultMessageNotifications,
GuildExplicitContentFilter,
GuildMFALevel,
GuildNSFWLevel,
GuildVerificationLevel,
} from "discord.js";
import log from "../../common/moderation/logging.js";
import difflib from "difflib";
/** @type {import("../../common/types/event").default<"guildUpdate">} */
export default async function event(oldGuild, newGuild) {
if (newGuild.id !== process.env.GUILD_ID) return;
const logs = [];
if (oldGuild.afkChannel?.id !== newGuild.afkChannel?.id) {
logs.push(
`Inactive channel set to ${newGuild.afkChannel?.toString() || "No inactive channel"}`,
);
}
if (oldGuild.afkTimeout !== newGuild.afkTimeout) {
logs.push(`Inactive timeout set to ${newGuild.afkTimeout}`);
}
if (oldGuild.bannerURL() !== newGuild.bannerURL()) {
logs.push(
`Server banner background ${
newGuild.bannerURL() ? `set to <${newGuild.bannerURL()}>` : newGuild.nameAcronym
}`,
);
}
if (oldGuild.defaultMessageNotifications !== newGuild.defaultMessageNotifications) {
logs.push(
`Default notification settings set to "${
{
[GuildDefaultMessageNotifications.AllMessages]: "All messages",
[GuildDefaultMessageNotifications.OnlyMentions]: "Only @mentions",
}[newGuild.defaultMessageNotifications]
}"`,
);
}
if (oldGuild.description !== newGuild.description) {
log(`✏ Server description was changed!`, "server", {
files: [
new AttachmentBuilder(
Buffer.from(
difflib
.unifiedDiff(
(oldGuild.description || "").split("\n"),
(newGuild.description || "").split("\n"),
)
.join("\n")
.replace(/^--- \n{2}\+\+\+ \n{2}@@ .+ @@\n{2}/, ""),
"utf-8",
),
{ name: "description.diff" },
),
],
});
}
if (oldGuild.discoverySplashURL() !== newGuild.discoverySplashURL()) {
logs.push(
`Server discovery listing cover image ${
newGuild.discoverySplashURL()
? `set to <${newGuild.discoverySplashURL()}>`
: "removed"
}`,
);
}
if (oldGuild.explicitContentFilter !== newGuild.explicitContentFilter) {
logs.push(
`Explicit media content filter set to "${
{
[GuildExplicitContentFilter.Disabled]: "Don't scan any media content.",
[GuildExplicitContentFilter.MembersWithoutRoles]:
"Scan media content from members without a role.",
[GuildExplicitContentFilter.AllMembers]: "Scan media content from all members.",
}[newGuild.explicitContentFilter]
}"`,
);
}
if (oldGuild.features.includes("COMMUNITY") !== newGuild.features.includes("COMMUNITY")) {
logs.push(`Community ${newGuild.features.includes("COMMUNITY") ? "en" : "dis"}abled`);
}
if (oldGuild.features.includes("DISCOVERABLE") !== newGuild.features.includes("DISCOVERABLE")) {
logs.push(
`Server Discovery ${newGuild.features.includes("DISCOVERABLE") ? "en" : "dis"}abled`,
);
}
if (oldGuild.features.includes("FEATURABLE") !== newGuild.features.includes("FEATURABLE")) {
logs.push(
`Server ${
newGuild.features.includes("FEATURABLE") ? "" : "un "
}featured on Server Discovery`,
);
}
if (
oldGuild.features.includes("HAS_DIRECTORY_ENTRY") !==
newGuild.features.includes("HAS_DIRECTORY_ENTRY")
) {
logs.push(
`➕ Invites ${newGuild.features.includes("HAS_DIRECTORY_ENTRY") ? "" : "un"}paused`,
);
}
if (
oldGuild.features.includes("INVITES_DISABLED") !==
newGuild.features.includes("INVITES_DISABLED")
) {
logs.push(
`Server ${
newGuild.features.includes("INVITES_DISABLED") ? "add" : "remov"
}ed from a directory channel`,
);
}
if (oldGuild.features.includes("HUB") !== newGuild.features.includes("HUB")) {
logs.push(`Server ${newGuild.features.includes("HUB") ? "" : "un"}made a Student Hub`);
}
if (
oldGuild.features.includes("LINKED_TO_HUB") !== newGuild.features.includes("LINKED_TO_HUB")
) {
logs.push(
`Server ${
newGuild.features.includes("LINKED_TO_HUB") ? "add" : "remov"
}ed from a Student Hub`,
);
}
if (
oldGuild.features.includes("MEMBER_VERIFICATION_GATE_ENABLED") !==
newGuild.features.includes("MEMBER_VERIFICATION_GATE_ENABLED")
) {
logs.push(
`Rules screening ${
newGuild.features.includes("MEMBER_VERIFICATION_GATE_ENABLED") ? "en" : "dis"
}abled`,
);
}
if (
oldGuild.features.includes("MONETIZATION_ENABLED") !==
newGuild.features.includes("MONETIZATION_ENABLED")
) {
logs.push(
`Monetization ${
newGuild.features.includes("MONETIZATION_ENABLED") ? "en" : "dis"
}abled`,
);
}
if (
oldGuild.features.includes("TICKETED_EVENTS_ENABLED") !==
newGuild.features.includes("TICKETED_EVENTS_ENABLED")
) {
logs.push(
`Ticketed events ${
newGuild.features.includes("TICKETED_EVENTS_ENABLED") ? "en" : "dis"
}abled`,
);
}
if (
oldGuild.features.includes("WELCOME_SCREEN_ENABLED") !==
newGuild.features.includes("WELCOME_SCREEN_ENABLED")
) {
logs.push(
`Welcome Screen ${
newGuild.features.includes("WELCOME_SCREEN_ENABLED") ? "en" : "dis"
}abled`,
);
}
if (oldGuild.iconURL() !== newGuild.iconURL()) {
logs.push(
`Server icon ${newGuild.iconURL() ? `set to <${newGuild.iconURL()}>` : "removed"}`,
);
}
if (oldGuild.mfaLevel !== newGuild.mfaLevel) {
logs.push(
`2FA requirement for moderation ${
{ [GuildMFALevel.None]: "dis", [GuildMFALevel.Elevated]: "en" }[newGuild.mfaLevel]
}abled`,
);
}
if (oldGuild.name !== newGuild.name) {
logs.push(`Server renamed to ${newGuild.name}`);
}
if (oldGuild.nsfwLevel !== newGuild.nsfwLevel) {
logs.push(
"Server " +
(newGuild.nsfwLevel === GuildNSFWLevel.Default
? "unmarked as NSFW"
: `marked as ${
{
[GuildNSFWLevel.Explicit]: "18+",
[GuildNSFWLevel.Safe]: "safe",
[GuildNSFWLevel.AgeRestricted]: "13+",
}[newGuild.nsfwLevel]
}`),
);
}
if (oldGuild.ownerId !== newGuild.ownerId) {
logs.push(`Server transferred to <@${newGuild.ownerId}>`);
}
if (oldGuild.partnered !== newGuild.partnered) {
logs.push(`Server ${newGuild.partnered ? "" : "un"}partnered`);
}
if (oldGuild.preferredLocale !== newGuild.preferredLocale) {
logs.push(`Server primary language switched to ${newGuild.preferredLocale}`);
}
if (oldGuild.premiumProgressBarEnabled !== newGuild.premiumProgressBarEnabled) {
logs.push(`Boost progress bar ${newGuild.premiumProgressBarEnabled ? "shown" : "hidden"}`);
}
if (oldGuild.publicUpdatesChannel?.id !== newGuild.publicUpdatesChannel?.id) {
logs.push(
"Community updates channel " +
(newGuild.publicUpdatesChannel
? "set to " + newGuild.publicUpdatesChannel.toString()
: "unset"),
);
}
if (oldGuild.rulesChannel?.id !== newGuild.rulesChannel?.id) {
logs.push(
"Rules or guidelines channel " +
(newGuild.rulesChannel ? "set to " + newGuild.rulesChannel.toString() : "unset"),
);
}
if (oldGuild.splashURL() !== newGuild.splashURL()) {
logs.push(
`Server invite background ${
newGuild.splashURL() ? `set to <${newGuild.splashURL()}>` : "removed"
}`,
);
}
if (oldGuild.systemChannel !== newGuild.systemChannel) {
logs.push(
"System messages channel " +
(newGuild.systemChannel ? "set to " + newGuild.systemChannel.toString() : "unset"),
);
}
if (oldGuild.vanityURLCode !== newGuild.vanityURLCode) {
logs.push(`Custom invite link set to ${newGuild.vanityURLCode}`);
}
if (oldGuild.verificationLevel !== newGuild.verificationLevel) {
logs.push(
`Verification level set to "${
{
[GuildVerificationLevel.None]: "Unrestricted",
[GuildVerificationLevel.Low]:
"Must have a verified email on their Discord account.",
[GuildVerificationLevel.Medium]:
"Must also be registered on Discord for longer than 5 minutes.",
[GuildVerificationLevel.High]:
"Must also be a member of this server for longer than 10 minutes.",
[GuildVerificationLevel.VeryHigh]:
"Must have a verified phone on their Discord account.",
}[newGuild.verificationLevel]
}"`,
);
}
if (oldGuild.verified !== newGuild.verified) {
logs.push(`Server ${newGuild.verified ? "" : "un"}verified`);
}
if (oldGuild.widgetChannel?.id !== newGuild.widgetChannel?.id) {
logs.push(
`Server widget invite channel ${
newGuild.widgetChannel ? "set to " + newGuild.widgetChannel.toString() : "unset"
}`,
);
}
if (oldGuild.widgetEnabled !== newGuild.widgetEnabled) {
logs.push(`Server widget ${newGuild.partnered ? "en" : "dis"}abled`);
}
if (oldGuild.maxVideoChannelUsers !== newGuild.maxVideoChannelUsers) {
logs.push(
`The max number of users allowed in a video channel changed to ${newGuild.maxVideoChannelUsers}`,
);
}
if (
oldGuild.systemChannelFlags.has("SuppressGuildReminderNotifications") !==
newGuild.systemChannelFlags.has("SuppressGuildReminderNotifications")
) {
logs.push(
`Helpful tips for server setup ${
newGuild.systemChannelFlags.has("SuppressGuildReminderNotifications") ? "dis" : "en"
}abled`,
);
}
if (
oldGuild.systemChannelFlags.has("SuppressJoinNotificationReplies") !==
newGuild.systemChannelFlags.has("SuppressJoinNotificationReplies")
) {
logs.push(
`Prompt to reply to welcome messages with a sticker ${
newGuild.systemChannelFlags.has("SuppressJoinNotificationReplies") ? "dis" : "en"
}abled`,
);
}
if (
oldGuild.systemChannelFlags.has("SuppressJoinNotifications") !==
newGuild.systemChannelFlags.has("SuppressJoinNotifications")
) {
logs.push(
`Random welcome messages when someone joins this server ${
newGuild.systemChannelFlags.has("SuppressJoinNotifications") ? "dis" : "en"
}abled`,
);
}
if (
oldGuild.systemChannelFlags.has("SuppressPremiumSubscriptions") !==
newGuild.systemChannelFlags.has("SuppressPremiumSubscriptions")
) {
logs.push(
`Messages when someone boosts this server ${
newGuild.systemChannelFlags.has("SuppressPremiumSubscriptions") ? "dis" : "en"
}abled`,
);
}
await Promise.all(logs.map((edit) => log("✏" + edit + `!`, "server")));
}