meow
This commit is contained in:
parent
2479564b8b
commit
cae2a37783
|
|
@ -11,8 +11,8 @@
|
||||||
"tail": "wrangler tail"
|
"tail": "wrangler tail"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20240909.0",
|
"@cloudflare/workers-types": "^4.20260617.1",
|
||||||
"typescript": "^5.5.4",
|
"typescript": "^6.0.3",
|
||||||
"wrangler": "^3.78.0"
|
"wrangler": "^4.101.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
951
pnpm-lock.yaml
951
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -32,6 +32,11 @@ export interface RawDiscordUser {
|
||||||
} | null;
|
} | null;
|
||||||
collectibles?: Record<string, unknown> | null;
|
collectibles?: Record<string, unknown> | null;
|
||||||
discriminator?: string;
|
discriminator?: string;
|
||||||
|
display_name_styles?: {
|
||||||
|
colors?: number[] | null;
|
||||||
|
font_id?: number | null;
|
||||||
|
effect_id?: number | null;
|
||||||
|
} | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RawProfileBadge {
|
export interface RawProfileBadge {
|
||||||
|
|
@ -43,7 +48,12 @@ export interface RawProfileBadge {
|
||||||
|
|
||||||
export interface RawProfileResponse {
|
export interface RawProfileResponse {
|
||||||
user?: RawDiscordUser & { bio?: string };
|
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[];
|
badges?: RawProfileBadge[];
|
||||||
connected_accounts?: Array<{ type: string; id: string; name: string; verified: boolean }>;
|
connected_accounts?: Array<{ type: string; id: string; name: string; verified: boolean }>;
|
||||||
premium_type?: number;
|
premium_type?: number;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,12 @@ function flagBadges(flags: number): UnifiedBadge[] {
|
||||||
return out;
|
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 pg = u.primary_guild;
|
||||||
const clan =
|
const clan =
|
||||||
pg && pg.tag && pg.identity_enabled && pg.identity_guild_id
|
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,
|
collectibles: (u.collectibles as Record<string, unknown> | null) ?? null,
|
||||||
bio,
|
bio,
|
||||||
pronouns,
|
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 u = profile.user;
|
||||||
const bio = profile.user_profile?.bio ?? u.bio ?? null;
|
const bio = profile.user_profile?.bio ?? u.bio ?? null;
|
||||||
const pronouns = profile.user_profile?.pronouns ?? 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[] = [];
|
const badges: UnifiedBadge[] = [];
|
||||||
// Flag badges from the user object (so classic badges are always present).
|
// 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,
|
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.
|
// Bot-only fallback.
|
||||||
const u = await fetchBotUser(env, id);
|
const u = await fetchBotUser(env, id);
|
||||||
if (!u) return null;
|
if (!u) return null;
|
||||||
return {
|
return {
|
||||||
user: buildUser(u, null, null),
|
user: buildUser(u, null, null, null),
|
||||||
badges: flagBadges(u.public_flags ?? u.flags ?? 0),
|
badges: flagBadges(u.public_flags ?? u.flags ?? 0),
|
||||||
connected_accounts: [],
|
connected_accounts: [],
|
||||||
source: "bot",
|
source: "bot",
|
||||||
|
|
|
||||||
11
src/types.ts
11
src/types.ts
|
|
@ -73,6 +73,17 @@ export interface UnifiedUser {
|
||||||
/** Rich profile only (needs user token); null otherwise. */
|
/** Rich profile only (needs user token); null otherwise. */
|
||||||
bio: string | null;
|
bio: string | null;
|
||||||
pronouns: 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 {
|
export interface UnifiedSpotify {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue