This commit is contained in:
Clove 2026-06-19 15:00:54 +01:00
parent 2479564b8b
commit cae2a37783
5 changed files with 480 additions and 526 deletions

View File

@ -11,8 +11,8 @@
"tail": "wrangler tail"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240909.0",
"typescript": "^5.5.4",
"wrangler": "^3.78.0"
"@cloudflare/workers-types": "^4.20260617.1",
"typescript": "^6.0.3",
"wrangler": "^4.101.0"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,11 @@ export interface RawDiscordUser {
} | null;
collectibles?: Record<string, unknown> | null;
discriminator?: string;
display_name_styles?: {
colors?: number[] | null;
font_id?: number | null;
effect_id?: number | null;
} | null;
}
export interface RawProfileBadge {
@ -43,7 +48,12 @@ export interface RawProfileBadge {
export interface RawProfileResponse {
user?: RawDiscordUser & { bio?: string };
user_profile?: { bio?: string; pronouns?: string; accent_color?: number | null };
user_profile?: {
bio?: string;
pronouns?: string;
accent_color?: number | null;
theme_colors?: number[] | null;
};
badges?: RawProfileBadge[];
connected_accounts?: Array<{ type: string; id: string; name: string; verified: boolean }>;
premium_type?: number;

View File

@ -46,7 +46,12 @@ function flagBadges(flags: number): UnifiedBadge[] {
return out;
}
function buildUser(u: RawDiscordUser, bio: string | null, pronouns: string | null): UnifiedUser {
function buildUser(
u: RawDiscordUser,
bio: string | null,
pronouns: string | null,
themeColors: number[] | null
): UnifiedUser {
const pg = u.primary_guild;
const clan =
pg && pg.tag && pg.identity_enabled && pg.identity_guild_id
@ -77,6 +82,16 @@ function buildUser(u: RawDiscordUser, bio: string | null, pronouns: string | nul
collectibles: (u.collectibles as Record<string, unknown> | null) ?? null,
bio,
pronouns,
theme_colors: themeColors,
display_name_styles: u.display_name_styles
? {
colors: Array.isArray(u.display_name_styles.colors)
? u.display_name_styles.colors
: null,
font_id: u.display_name_styles.font_id ?? null,
effect_id: u.display_name_styles.effect_id ?? null,
}
: null,
};
}
@ -140,6 +155,11 @@ async function buildFreshProfile(env: Env, id: string): Promise<ProfileResult |
const u = profile.user;
const bio = profile.user_profile?.bio ?? u.bio ?? null;
const pronouns = profile.user_profile?.pronouns ?? null;
const themeColors =
Array.isArray(profile.user_profile?.theme_colors) &&
profile.user_profile!.theme_colors!.length >= 2
? profile.user_profile!.theme_colors!
: null;
const badges: UnifiedBadge[] = [];
// Flag badges from the user object (so classic badges are always present).
@ -164,14 +184,14 @@ async function buildFreshProfile(env: Env, id: string): Promise<ProfileResult |
verified: !!c.verified,
}));
return { user: buildUser(u, bio, pronouns), badges, connected_accounts: connected, source: "user" };
return { user: buildUser(u, bio, pronouns, themeColors), badges, connected_accounts: connected, source: "user" };
}
// Bot-only fallback.
const u = await fetchBotUser(env, id);
if (!u) return null;
return {
user: buildUser(u, null, null),
user: buildUser(u, null, null, null),
badges: flagBadges(u.public_flags ?? u.flags ?? 0),
connected_accounts: [],
source: "bot",

View File

@ -73,6 +73,17 @@ export interface UnifiedUser {
/** Rich profile only (needs user token); null otherwise. */
bio: string | null;
pronouns: string | null;
/** Nitro profile gradient — [top, bottom] ints; null if not set. */
theme_colors: number[] | null;
/** Nitro display-name styling — gradient colours + font/effect ids. */
display_name_styles: UnifiedDisplayNameStyles | null;
}
export interface UnifiedDisplayNameStyles {
/** 1 or 2 ints; the name-text gradient stops. */
colors: number[] | null;
font_id: number | null;
effect_id: number | null;
}
export interface UnifiedSpotify {