blob: 2cb1de8ca647d5d3d2ec53756681cc24220924ea [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);
7 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger;
8 const auditLog = await getAuditLog(after, "GUILD_UPDATE");
9 const audit = auditLog.entries.filter(entry => entry.target.id === after.id).first();
10 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
32 if (before.name !== after.name) list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
33 if (before.icon !== after.icon) list["icon"] = entry([before.icon, after.icon], `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`);
34 if (before.splash !== after.splash) list["splash"] = entry([before.splash, after.splash], `[Before](${before.splashURL()}) -> [After](${after.splashURL()})`);
35 if (before.banner !== after.banner) list["banner"] = entry([before.banner, after.banner], `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})`);
36 if (before.owner !== after.owner) list["owner"] = entry([before.owner, after.owner], `${renderUser(before.owner.user)} -> ${renderUser(after.owner.user)}`);
37 if (before.verificationLevel !== after.verificationLevel) list["verificationLevel"] = entry([verificationLevels[before.verificationLevel], verificationLevels[after.verificationLevel]], `${verificationLevels[before.verificationLevel]} -> ${verificationLevels[after.verificationLevel]}`);
38 if (before.explicitContentFilter !== after.explicitContentFilter) list["explicitContentFilter"] = entry([explicitContentFilterLevels[before.explicitContentFilter], explicitContentFilterLevels[after.explicitContentFilter]], `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${explicitContentFilterLevels[after.explicitContentFilter]}`);
39 if (before.mfaLevel !== after.mfaLevel) list["2 factor authentication"] = entry([MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]], `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}`);
40
41 if (!(Object.keys(list).length)) return;
42 list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()));
43 list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor));
44 const data = {
45 meta: {
46 type: "guildUpdate",
47 displayName: "Guild Edited",
48 calculateType: "guildUpdate",
49 color: NucleusColors.yellow,
50 emoji: "GUILD.YELLOW",
51 timestamp: new Date().getTime()
52 },
53 list: list,
54 hidden: {
55 guild: after.id
pineafane625d782022-05-09 18:04:32 +010056 }
pineafan63fc5e22022-08-04 22:04:10 +010057 };
58 log(data);
pineafane625d782022-05-09 18:04:32 +010059}