pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 1 | import { callback as statsChannelUpdate } from '../reflex/statsChannelUpdate.js'; |
| 2 | |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 3 | export const event = 'guildUpdate' |
| 4 | |
| 5 | export async function callback(client, before, after) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 6 | try { await statsChannelUpdate(client, after.me); } catch(e) { console.log(e)} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 7 | try { |
| 8 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger |
| 9 | let auditLog = await getAuditLog(after, 'GUILD_UPDATE'); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 10 | let audit = auditLog.entries.filter(entry => entry.target.id === after.id).first(); |
| 11 | if (audit.executor.id === client.user.id) return; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 12 | 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 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 33 | 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]}`); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 41 | |
| 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 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 59 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 60 | } catch (e) {} |
| 61 | } |