blob: a165770fd6db74d93134393ea97d648df2679431 [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 Grey11236ba2022-08-08 21:13:33 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01008 const auditLog = await getAuditLog(after, "GUILD_UPDATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01009 const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010010 if (audit.executor.id === client.user.id) return;
11 const list = {};
pineafane625d782022-05-09 18:04:32 +010012
pineafan63fc5e22022-08-04 22:04:10 +010013 const verificationLevels = {
14 NONE: "Unrestricted",
15 LOW: "Verified email",
16 MEDIUM: "Registered (5 minutes)",
17 HIGH: "Member (10 minutes)",
18 VERY_HIGH: "Verified phone"
19 };
20
21 const explicitContentFilterLevels = {
22 DISABLED: "Disabled",
23 MEMBERS_WITHOUT_ROLES: "Members without roles",
24 ALL_MEMBERS: "All members"
25 };
26
27 const MFALevels = {
28 NONE: "None",
29 ELEVATED: "Enabled"
30 };
31
Skyler Grey11236ba2022-08-08 21:13:33 +010032 if (before.name !== after.name) list.name = entry([before.name, after.name], `${before.name} -> ${after.name}`);
Skyler Grey75ea9172022-08-06 10:22:23 +010033 if (before.icon !== after.icon)
Skyler Grey11236ba2022-08-08 21:13:33 +010034 list.icon = entry([before.icon, after.icon], `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`);
Skyler Grey75ea9172022-08-06 10:22:23 +010035 if (before.splash !== after.splash)
36 list.splash = entry(
37 [before.splash, after.splash],
38 `[Before](${before.splashURL()}) -> [After](${after.splashURL()})`
39 );
40 if (before.banner !== after.banner)
41 list.banner = entry(
42 [before.banner, after.banner],
43 `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})`
44 );
45 if (before.owner !== after.owner)
46 list.owner = entry(
47 [before.owner, after.owner],
Skyler Grey11236ba2022-08-08 21:13:33 +010048 `${renderUser(before.owner.user)} -> ${renderUser(after.owner.user)}`
Skyler Grey75ea9172022-08-06 10:22:23 +010049 );
50 if (before.verificationLevel !== after.verificationLevel)
51 list.verificationLevel = entry(
Skyler Grey11236ba2022-08-08 21:13:33 +010052 [verificationLevels[before.verificationLevel], verificationLevels[after.verificationLevel]],
53 `${verificationLevels[before.verificationLevel]} -> ${verificationLevels[after.verificationLevel]}`
Skyler Grey75ea9172022-08-06 10:22:23 +010054 );
55 if (before.explicitContentFilter !== after.explicitContentFilter)
56 list.explicitContentFilter = entry(
57 [
58 explicitContentFilterLevels[before.explicitContentFilter],
59 explicitContentFilterLevels[after.explicitContentFilter]
60 ],
61 `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${
62 explicitContentFilterLevels[after.explicitContentFilter]
63 }`
64 );
65 if (before.mfaLevel !== after.mfaLevel)
66 list["2 factor authentication"] = entry(
67 [MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]],
68 `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}`
69 );
pineafan63fc5e22022-08-04 22:04:10 +010070
Skyler Grey75ea9172022-08-06 10:22:23 +010071 if (!Object.keys(list).length) return;
Skyler Grey11236ba2022-08-08 21:13:33 +010072 list.updated = entry(new Date().getTime(), renderDelta(new Date().getTime()));
Skyler Grey75ea9172022-08-06 10:22:23 +010073 list.updatedBy = entry(audit.executor.id, renderUser(audit.executor));
pineafan63fc5e22022-08-04 22:04:10 +010074 const data = {
75 meta: {
76 type: "guildUpdate",
77 displayName: "Guild Edited",
78 calculateType: "guildUpdate",
79 color: NucleusColors.yellow,
80 emoji: "GUILD.YELLOW",
81 timestamp: new Date().getTime()
82 },
83 list: list,
84 hidden: {
85 guild: after.id
pineafane625d782022-05-09 18:04:32 +010086 }
pineafan63fc5e22022-08-04 22:04:10 +010087 };
88 log(data);
pineafane625d782022-05-09 18:04:32 +010089}