Skip to content

Commit

Permalink
Update and fixes for api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhincore committed Jan 2, 2025
1 parent 25476d2 commit 6f57470
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
31 changes: 18 additions & 13 deletions src/lib/server/lizzy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -88,7 +88,12 @@ let memberCache: Promise<DiscordMember[]> | null = null;
export async function fetchDiscordMembers(): Promise<DiscordMember[]> {
// 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;
}
14 changes: 8 additions & 6 deletions src/lib/server/members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export async function fetchTeams() {

export async function getCachedMembers() {
if (!cache) cache = await _fetchMembers();
console.log(cache.memberMap.zhincore);
return cache;
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
};
}

Expand Down

0 comments on commit 6f57470

Please sign in to comment.