pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { callback as statsChannelUpdate } from "../reflex/statsChannelUpdate.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 2 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | export const event = "guildUpdate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 4 | |
| 5 | export async function callback(client, before, after) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | await statsChannelUpdate(client, after.me); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 7 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = |
| 8 | after.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | const auditLog = await getAuditLog(after, "GUILD_UPDATE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 10 | const audit = auditLog.entries |
| 11 | .filter((entry) => entry.target.id === after.id) |
| 12 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | if (audit.executor.id === client.user.id) return; |
| 14 | const list = {}; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 15 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 16 | const verificationLevels = { |
| 17 | NONE: "Unrestricted", |
| 18 | LOW: "Verified email", |
| 19 | MEDIUM: "Registered (5 minutes)", |
| 20 | HIGH: "Member (10 minutes)", |
| 21 | VERY_HIGH: "Verified phone" |
| 22 | }; |
| 23 | |
| 24 | const explicitContentFilterLevels = { |
| 25 | DISABLED: "Disabled", |
| 26 | MEMBERS_WITHOUT_ROLES: "Members without roles", |
| 27 | ALL_MEMBERS: "All members" |
| 28 | }; |
| 29 | |
| 30 | const MFALevels = { |
| 31 | NONE: "None", |
| 32 | ELEVATED: "Enabled" |
| 33 | }; |
| 34 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | if (before.name !== after.name) |
| 36 | list.name = entry( |
| 37 | [before.name, after.name], |
| 38 | `${before.name} -> ${after.name}` |
| 39 | ); |
| 40 | if (before.icon !== after.icon) |
| 41 | list.icon = entry( |
| 42 | [before.icon, after.icon], |
| 43 | `[Before](${before.iconURL()}) -> [After](${after.iconURL()})` |
| 44 | ); |
| 45 | if (before.splash !== after.splash) |
| 46 | list.splash = entry( |
| 47 | [before.splash, after.splash], |
| 48 | `[Before](${before.splashURL()}) -> [After](${after.splashURL()})` |
| 49 | ); |
| 50 | if (before.banner !== after.banner) |
| 51 | list.banner = entry( |
| 52 | [before.banner, after.banner], |
| 53 | `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})` |
| 54 | ); |
| 55 | if (before.owner !== after.owner) |
| 56 | list.owner = entry( |
| 57 | [before.owner, after.owner], |
| 58 | `${renderUser(before.owner.user)} -> ${renderUser( |
| 59 | after.owner.user |
| 60 | )}` |
| 61 | ); |
| 62 | if (before.verificationLevel !== after.verificationLevel) |
| 63 | list.verificationLevel = entry( |
| 64 | [ |
| 65 | verificationLevels[before.verificationLevel], |
| 66 | verificationLevels[after.verificationLevel] |
| 67 | ], |
| 68 | `${verificationLevels[before.verificationLevel]} -> ${ |
| 69 | verificationLevels[after.verificationLevel] |
| 70 | }` |
| 71 | ); |
| 72 | if (before.explicitContentFilter !== after.explicitContentFilter) |
| 73 | list.explicitContentFilter = entry( |
| 74 | [ |
| 75 | explicitContentFilterLevels[before.explicitContentFilter], |
| 76 | explicitContentFilterLevels[after.explicitContentFilter] |
| 77 | ], |
| 78 | `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${ |
| 79 | explicitContentFilterLevels[after.explicitContentFilter] |
| 80 | }` |
| 81 | ); |
| 82 | if (before.mfaLevel !== after.mfaLevel) |
| 83 | list["2 factor authentication"] = entry( |
| 84 | [MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]], |
| 85 | `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}` |
| 86 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 87 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | if (!Object.keys(list).length) return; |
| 89 | list.updated = entry( |
| 90 | new Date().getTime(), |
| 91 | renderDelta(new Date().getTime()) |
| 92 | ); |
| 93 | list.updatedBy = entry(audit.executor.id, renderUser(audit.executor)); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 94 | const data = { |
| 95 | meta: { |
| 96 | type: "guildUpdate", |
| 97 | displayName: "Guild Edited", |
| 98 | calculateType: "guildUpdate", |
| 99 | color: NucleusColors.yellow, |
| 100 | emoji: "GUILD.YELLOW", |
| 101 | timestamp: new Date().getTime() |
| 102 | }, |
| 103 | list: list, |
| 104 | hidden: { |
| 105 | guild: after.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 106 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 107 | }; |
| 108 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 109 | } |