mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { fetchBlitz } from "./fetchBlitz";
|
|
import { normalizeIds } from "./normalizeIds";
|
|
import type { Region } from "./regions";
|
|
|
|
type IndividualClanAccountInfo = {
|
|
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;
|
|
|
|
interface ClanAccountInfo {
|
|
[accountId: number]: IndividualClanAccountInfo;
|
|
}
|
|
|
|
export async function getClanAccountInfo<
|
|
Ids extends number | number[],
|
|
ReturnType = Ids extends number
|
|
? IndividualClanAccountInfo
|
|
: IndividualClanAccountInfo[],
|
|
>(region: Region, ids: Ids, extra: string[] = []) {
|
|
const object = await fetchBlitz<ClanAccountInfo>(
|
|
region,
|
|
"clans/accountinfo",
|
|
{
|
|
account_id: normalizeIds(ids),
|
|
extra: extra.length === 0 ? undefined : extra.join(","),
|
|
}
|
|
);
|
|
|
|
if (typeof ids === "number") {
|
|
return object[ids as number] as ReturnType;
|
|
} else {
|
|
return ids.map((id) => object[id]) as ReturnType;
|
|
}
|
|
}
|