Files
blitzkit/packages/core/src/blitz/getClanAccountInfo.ts
T

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-10-12 15:05:58 +00:00
import { fetchBlitz } from "./fetchBlitz";
import { normalizeIds } from "./normalizeIds";
2025-10-13 23:20:26 -05:00
import type { Region } from "./regions";
2023-10-12 13:00:33 -05:00
2024-03-12 23:36:56 -05:00
type IndividualClanAccountInfo = {
2023-10-12 13:00:33 -05:00
account_id: number;
joined_at: number;
clan_id: number;
role: string;
account_name: string;
clan?: {
members_count: number;
name: string;
created_at: number;
tag: string;
clan_id: number;
emblem_set_id: number;
};
} | null;
2024-03-12 23:36:56 -05:00
interface ClanAccountInfo {
2023-10-12 13:00:33 -05:00
[accountId: number]: IndividualClanAccountInfo;
}
export async function getClanAccountInfo<
Ids extends number | number[],
ReturnType = Ids extends number
? IndividualClanAccountInfo
: IndividualClanAccountInfo[],
2024-04-15 13:19:25 -05:00
>(region: Region, ids: Ids, extra: string[] = []) {
2023-10-14 10:58:48 -05:00
const object = await fetchBlitz<ClanAccountInfo>(
2024-04-15 13:19:25 -05:00
region,
2025-10-12 15:05:58 +00:00
"clans/accountinfo",
2024-04-15 13:19:25 -05:00
{
account_id: normalizeIds(ids),
2025-10-12 15:05:58 +00:00
extra: extra.length === 0 ? undefined : extra.join(","),
}
2023-10-12 13:00:33 -05:00
);
2025-10-12 15:05:58 +00:00
if (typeof ids === "number") {
2023-10-12 13:00:33 -05:00
return object[ids as number] as ReturnType;
} else {
return ids.map((id) => object[id]) as ReturnType;
}
}