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