blob: 2c878077bcdc314d380566a0471f3927f254e5dc [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { callback as statsChannelUpdate } from "../reflex/statsChannelUpdate.js";
pineafane23c4ec2022-07-27 21:56:27 +01002
pineafan63fc5e22022-08-04 22:04:10 +01003export const event = "guildUpdate";
pineafane625d782022-05-09 18:04:32 +01004
5export async function callback(client, before, after) {
pineafan63fc5e22022-08-04 22:04:10 +01006 await statsChannelUpdate(client, after.me);
Skyler Grey75ea9172022-08-06 10:22:23 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } =
8 after.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(after, "GUILD_UPDATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010010 const audit = auditLog.entries
11 .filter((entry) => entry.target.id === after.id)
12 .first();
pineafan63fc5e22022-08-04 22:04:10 +010013 if (audit.executor.id === client.user.id) return;
14 const list = {};
pineafane625d782022-05-09 18:04:32 +010015
pineafan63fc5e22022-08-04 22:04:10 +010016 const verificationLevels = {
17 NONE: "Unrestricted",
18 LOW: "Verified email",
19 MEDIUM: "Registered (5 minutes)",
20 HIGH: "Member (10 minutes)",
21 VERY_HIGH: "Verified phone"
22 };
23
24 const explicitContentFilterLevels = {
25 DISABLED: "Disabled",
26 MEMBERS_WITHOUT_ROLES: "Members without roles",
27 ALL_MEMBERS: "All members"
28 };
29
30 const MFALevels = {
31 NONE: "None",
32 ELEVATED: "Enabled"
33 };
34
Skyler Grey75ea9172022-08-06 10:22:23 +010035 if (before.name !== after.name)
36 list.name = entry(
37 [before.name, after.name],
38 `${before.name} -> ${after.name}`
39 );
40 if (before.icon !== after.icon)
41 list.icon = entry(
42 [before.icon, after.icon],
43 `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`
44 );
45 if (before.splash !== after.splash)
46 list.splash = entry(
47 [before.splash, after.splash],
48 `[Before](${before.splashURL()}) -> [After](${after.splashURL()})`
49 );
50 if (before.banner !== after.banner)
51 list.banner = entry(
52 [before.banner, after.banner],
53 `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})`
54 );
55 if (before.owner !== after.owner)
56 list.owner = entry(
57 [before.owner, after.owner],
58 `${renderUser(before.owner.user)} -> ${renderUser(
59 after.owner.user
60 )}`
61 );
62 if (before.verificationLevel !== after.verificationLevel)
63 list.verificationLevel = entry(
64 [
65 verificationLevels[before.verificationLevel],
66 verificationLevels[after.verificationLevel]
67 ],
68 `${verificationLevels[before.verificationLevel]} -> ${
69 verificationLevels[after.verificationLevel]
70 }`
71 );
72 if (before.explicitContentFilter !== after.explicitContentFilter)
73 list.explicitContentFilter = entry(
74 [
75 explicitContentFilterLevels[before.explicitContentFilter],
76 explicitContentFilterLevels[after.explicitContentFilter]
77 ],
78 `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${
79 explicitContentFilterLevels[after.explicitContentFilter]
80 }`
81 );
82 if (before.mfaLevel !== after.mfaLevel)
83 list["2 factor authentication"] = entry(
84 [MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]],
85 `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}`
86 );
pineafan63fc5e22022-08-04 22:04:10 +010087
Skyler Grey75ea9172022-08-06 10:22:23 +010088 if (!Object.keys(list).length) return;
89 list.updated = entry(
90 new Date().getTime(),
91 renderDelta(new Date().getTime())
92 );
93 list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
pineafan63fc5e22022-08-04 22:04:10 +010094 const data = {
95 meta: {
96 type: "guildUpdate",
97 displayName: "Guild Edited",
98 calculateType: "guildUpdate",
99 color: NucleusColors.yellow,
100 emoji: "GUILD.YELLOW",
101 timestamp: new Date().getTime()
102 },
103 list: list,
104 hidden: {
105 guild: after.id
pineafane625d782022-05-09 18:04:32 +0100106 }
pineafan63fc5e22022-08-04 22:04:10 +0100107 };
108 log(data);
pineafane625d782022-05-09 18:04:32 +0100109}