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