pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 1 | export const event = 'guildUpdate' |
| 2 | |
| 3 | export 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 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 56 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 57 | } catch (e) {} |
| 58 | } |