diff --git a/src/lib/server/lizzy.ts b/src/lib/server/lizzy.ts index 2aee96b..a70ac6a 100644 --- a/src/lib/server/lizzy.ts +++ b/src/lib/server/lizzy.ts @@ -17,18 +17,18 @@ export interface DiscordMember { ID: string; Bot: boolean; Roles: Role[]; - CustomData: null | Partial<{ - id: string; - user: string; - userid: string; - nexusmods: string; - nexusmodsVerified: boolean; - github: string; - githubVerified: boolean; - theme: Theme; - description: string; - style: "lowercase" | "uppercase"; - }>; + CustomData: null | Record< + `${number}`, + Partial<{ + theme: Theme; + style: "lowercase" | "uppercase"; + nexusmods: string; + nexusmodsVerified: boolean; + github: string; + githubVerified: boolean; + description: string; + }> + >; NexusData: null | { mods: { nodes: NexusMod[]; @@ -88,7 +88,12 @@ let memberCache: Promise | null = null; export async function fetchDiscordMembers(): Promise { // Cache in development if (!dev || !memberCache) { - memberCache = fetchLizzy("/api/discord/web?q=" + DISCORD_SERVER_ID).then((r) => r.json()); + memberCache = fetchLizzy("/api/v2/web?q=" + DISCORD_SERVER_ID) + .then((r) => r.json()) + .catch((e) => { + memberCache = null; + throw e; + }); } return memberCache; } diff --git a/src/lib/server/members.ts b/src/lib/server/members.ts index 89acb9f..c50df3c 100644 --- a/src/lib/server/members.ts +++ b/src/lib/server/members.ts @@ -32,7 +32,6 @@ export async function fetchTeams() { export async function getCachedMembers() { if (!cache) cache = await _fetchMembers(); - console.log(cache.memberMap.zhincore); return cache; } @@ -80,7 +79,13 @@ function processMembers(members: DiscordMember[]) { function createTeamMember(discordMember: DiscordMember): TeamMember { const override = members[discordMember.Username]; - const style = override?.CustomData?.style || discordMember.CustomData?.style || "uppercase"; + const customDataOrigin = discordMember.CustomData + ? Object.values(discordMember.CustomData).reduce((acc, v) => ({ ...acc, ...v }), {}) + : null; + + const CustomData = + discordMember.CustomData || override?.CustomData ? { ...customDataOrigin, ...override?.CustomData } : null; + const style = CustomData?.style || "uppercase"; return { ...discordMember, @@ -97,10 +102,7 @@ function createTeamMember(discordMember: DiscordMember): TeamMember { ...override, // Merge custom data with override - CustomData: - discordMember.CustomData || override?.CustomData - ? { ...discordMember.CustomData, ...override?.CustomData } - : null, + CustomData, }; }