PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 1 | import type { NucleusClient } from "../utils/client.js"; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 2 | import { AuditLogEvent, Guild, GuildAuditLogsEntry } from "discord.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import { callback as statsChannelUpdate } from "../reflex/statsChannelUpdate.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 4 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | export const event = "guildUpdate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 7 | export async function callback(client: NucleusClient, before: Guild, after: Guild) { |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 8 | await statsChannelUpdate(client, after.members.me!); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 9 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger; |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 10 | const auditLog = (await getAuditLog(after, AuditLogEvent.GuildUpdate)) |
| 11 | .filter((entry: GuildAuditLogsEntry) => (entry.target as Guild)!.id === after.id)[0]!; |
| 12 | if (auditLog.executor!.id === client.user!.id) return; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 13 | const list: Record<string, ReturnType<typeof entry>> = {}; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 14 | |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 15 | const verificationLevels = [ |
| 16 | "Unrestricted", |
| 17 | "Verified email", |
| 18 | "Registered (5 minutes)", |
| 19 | "Member (10 minutes)", |
| 20 | "Verified phone" |
| 21 | ]; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 23 | const explicitContentFilterLevels = [ |
| 24 | "Disabled", |
| 25 | "Members without roles", |
| 26 | "All members" |
| 27 | ]; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 29 | const MFALevels = [ |
| 30 | "None", |
| 31 | "Enabled" |
| 32 | ]; |
| 33 | |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 34 | const beforeOwner = await before.fetchOwner(); |
| 35 | const afterOwner = await after.fetchOwner(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 36 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 37 | 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] | 38 | if (before.icon !== after.icon) |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 39 | 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] | 40 | if (before.splash !== after.splash) |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 41 | list["splash"] = entry( |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 42 | [before.splash!, after.splash!], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 43 | `[Before](${before.splashURL()}) -> [After](${after.splashURL()})` |
| 44 | ); |
| 45 | if (before.banner !== after.banner) |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 46 | list["banner"] = entry( |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 47 | [before.banner!, after.banner!], |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})` |
| 49 | ); |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 50 | if (beforeOwner !== afterOwner) |
| 51 | list["owner"] = entry( |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 52 | [beforeOwner.id, afterOwner.id], |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 53 | `${renderUser(beforeOwner.user)} -> ${renderUser(afterOwner.user)}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | ); |
| 55 | if (before.verificationLevel !== after.verificationLevel) |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 56 | list["verificationLevel"] = entry( |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 57 | [verificationLevels[before.verificationLevel.valueOf()]!, verificationLevels[before.verificationLevel.valueOf()]!], |
| 58 | `${verificationLevels[before.verificationLevel.valueOf()]} -> ${verificationLevels[before.verificationLevel.valueOf()]}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 59 | ); |
| 60 | if (before.explicitContentFilter !== after.explicitContentFilter) |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 61 | list["explicitContentFilter"] = entry( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 62 | [ |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 63 | explicitContentFilterLevels[before.explicitContentFilter.valueOf()]!, |
| 64 | explicitContentFilterLevels[after.explicitContentFilter.valueOf()]! |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 65 | ], |
| 66 | `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${ |
| 67 | explicitContentFilterLevels[after.explicitContentFilter] |
| 68 | }` |
| 69 | ); |
| 70 | if (before.mfaLevel !== after.mfaLevel) |
| 71 | list["2 factor authentication"] = entry( |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 72 | [MFALevels[before.mfaLevel.valueOf()]!, MFALevels[after.mfaLevel.valueOf()]!], |
| 73 | `${MFALevels[before.mfaLevel.valueOf()]} -> ${MFALevels[after.mfaLevel.valueOf()]}` |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 74 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 75 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 76 | if (!Object.keys(list).length) return; |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 77 | list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime())); |
TheCodedProf | a16d167 | 2023-01-18 18:58:34 -0500 | [diff] [blame] | 78 | list["updatedBy"] = entry(auditLog.executor!.id, renderUser(auditLog.executor!)); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 79 | const data = { |
| 80 | meta: { |
| 81 | type: "guildUpdate", |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 82 | displayName: "Server Edited", |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 83 | calculateType: "guildUpdate", |
| 84 | color: NucleusColors.yellow, |
| 85 | emoji: "GUILD.YELLOW", |
| 86 | timestamp: new Date().getTime() |
| 87 | }, |
| 88 | list: list, |
| 89 | hidden: { |
| 90 | guild: after.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 91 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 92 | }; |
| 93 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 94 | } |