-
Notifications
You must be signed in to change notification settings - Fork 13
/
update.js
124 lines (112 loc) · 3.92 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
import {
AttachmentBuilder,
ChannelType,
escapeMarkdown,
ThreadAutoArchiveDuration,
VideoQualityMode,
} from "discord.js";
import log from "../../common/moderation/logging.js";
import difflib from "difflib";
/** @type {import("../../common/types/event").default<"channelUpdate">} */
export default async function event(oldChannel, newChannel) {
if (
newChannel.isDMBased() ||
oldChannel.isDMBased() ||
newChannel.guild.id !== process.env.GUILD_ID
)
return;
const edits = [];
if (oldChannel.name !== newChannel.name)
edits.push(" was renamed to " + escapeMarkdown(newChannel.name));
if (oldChannel.type !== newChannel.type)
edits.push(
" was made into a" +
{
[ChannelType.GuildText]: " text",
[ChannelType.GuildVoice]: " voice",
[ChannelType.GuildCategory]: " category",
[ChannelType.GuildAnnouncement]: "n announcement",
[ChannelType.GuildStageVoice]: " stage",
[ChannelType.GuildForum]: " forum",
}[newChannel.type] +
" channel",
);
if (oldChannel.rawPosition !== newChannel.rawPosition)
edits.push(" was moved to position " + newChannel.rawPosition);
if (oldChannel.isTextBased() && newChannel.isTextBased()) {
if (oldChannel.nsfw !== newChannel.nsfw)
edits.push(` was made ${newChannel.nsfw ? "" : "non-"}age-restricted`);
oldChannel.rateLimitPerUser !== newChannel.rateLimitPerUser &&
edits.push("’s slowmode was set to " + newChannel.rateLimitPerUser + " seconds");
}
if (oldChannel.isVoiceBased() && newChannel.isVoiceBased()) {
oldChannel.bitrate !== newChannel.bitrate &&
edits.push("’s bitrate was set to " + newChannel.bitrate + "kbps");
oldChannel.userLimit !== newChannel.userLimit &&
edits.push(
"’s user limit was " + newChannel.userLimit
? "set to " + newChannel.userLimit + " users"
: "removed",
);
oldChannel.rtcRegion !== newChannel.rtcRegion &&
edits.push("’s region override was set to " + newChannel.rtcRegion || "Automatic");
}
if (
(oldChannel.type === ChannelType.GuildText ||
oldChannel.type === ChannelType.GuildForum ||
oldChannel.type === ChannelType.GuildAnnouncement) &&
(newChannel.type === ChannelType.GuildText ||
newChannel.type === ChannelType.GuildForum ||
newChannel.type === ChannelType.GuildAnnouncement)
) {
if (oldChannel.topic !== newChannel.topic) {
log(`✏ Channel ${newChannel.toString()}’s topic was changed!`, "channels", {
files: [
new AttachmentBuilder(
Buffer.from(
difflib
.unifiedDiff(
(oldChannel.topic || "").split("\n"),
(newChannel.topic || "").split("\n"),
)
.join("\n")
.replace(/^--- \n{2}\+\+\+ \n{2}@@ .+ @@\n{2}/, ""),
"utf-8",
),
{ name: "topic.diff" },
),
],
});
}
oldChannel.defaultAutoArchiveDuration !== newChannel.defaultAutoArchiveDuration &&
edits.push(
"’s hide after inactivity time was set to " +
{
[ThreadAutoArchiveDuration.OneHour]: "1 Hour",
[ThreadAutoArchiveDuration.OneDay]: "24 Hours",
[ThreadAutoArchiveDuration.ThreeDays]: "3 Days",
[ThreadAutoArchiveDuration.OneWeek]: "1 Week",
}[newChannel.defaultAutoArchiveDuration || ThreadAutoArchiveDuration.OneDay] ||
newChannel.defaultAutoArchiveDuration,
);
}
if (oldChannel.type === ChannelType.GuildForum && newChannel.type === ChannelType.GuildForum) {
// TODO
oldChannel.availableTags;
oldChannel.defaultReactionEmoji;
oldChannel.defaultThreadRateLimitPerUser;
}
if (oldChannel.type === ChannelType.GuildVoice && newChannel.type === ChannelType.GuildVoice)
oldChannel.videoQualityMode !== newChannel.videoQualityMode &&
edits.push(
`’s video quality set to ${
{
[VideoQualityMode.Auto]: "Auto",
[VideoQualityMode.Full]: "720p",
}[newChannel.videoQualityMode || VideoQualityMode.Auto]
}`,
);
await Promise.all(
edits.map((edit) => log(`✏ Channel ${newChannel.toString()}${edit}!`, "channels")),
);
}