blob: 400cfe4ef2b445a2464c73cb7d475f34562c301c [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001export const event = 'guildUpdate'
2
3export async function callback(client, before, after) {
4 try {
5 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger
6 let auditLog = await getAuditLog(after, 'GUILD_UPDATE');
7 let audit = auditLog.entries.filter(entry => entry.target.id == after.id).first();
8 if (audit.executor.id == client.user.id) return;
9 let list = {}
10
11 const verificationLevels = {
12 NONE: 'Unrestricted',
13 LOW: 'Verified email',
14 MEDIUM: 'Registered (5 minutes)',
15 HIGH: 'Member (10 minutes)',
16 VERY_HIGH: 'Verified phone'
17 }
18
19 const explicitContentFilterLevels = {
20 DISABLED: 'Disabled',
21 MEMBERS_WITHOUT_ROLES: 'Members without roles',
22 ALL_MEMBERS: 'All members'
23 }
24
25 const MFALevels = {
26 NONE: 'None',
27 ELEVATED: 'Enabled'
28 }
29
30 if (before.name != after.name) list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
31 if (before.icon != after.icon) list["icon"] = entry([before.icon, after.icon], `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`);
32 if (before.splash != after.splash) list["splash"] = entry([before.splash, after.splash], `[Before](${before.splashURL()}) -> [After](${after.splashURL()})`);
33 if (before.banner != after.banner) list["banner"] = entry([before.banner, after.banner], `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})`);
34 if (before.owner != after.owner) list["owner"] = entry([before.owner, after.owner], `${renderUser(before.owner.user)} -> ${renderUser(after.owner.user)}`);
35 if (before.verificationLevel != after.verificationLevel) list["verificationLevel"] = entry([verificationLevels[before.verificationLevel], verificationLevels[after.verificationLevel]], `${verificationLevels[before.verificationLevel]} -> ${verificationLevels[after.verificationLevel]}`);
36 if (before.explicitContentFilter != after.explicitContentFilter) list["explicitContentFilter"] = entry([explicitContentFilterLevels[before.explicitContentFilter], explicitContentFilterLevels[after.explicitContentFilter]], `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${explicitContentFilterLevels[after.explicitContentFilter]}`);
37 if (before.mfaLevel != after.mfaLevel) list["2 factor authentication"] = entry([MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]], `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}`);
38
39 if (!(Object.keys(list).length)) return;
40 list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()))
41 list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor))
42 let data = {
43 meta: {
44 type: 'guildUpdate',
45 displayName: 'Guild Edited',
46 calculateType: 'guildUpdate',
47 color: NucleusColors.yellow,
48 emoji: "GUILD.YELLOW",
49 timestamp: new Date().getTime()
50 },
51 list: list,
52 hidden: {
53 guild: after.id
54 }
55 }
56 log(data, after.client);
57 } catch (e) {}
58}