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

45 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-09-08 10:17:40 -05:00
import { fetchBlitz, Region } from '@blitzkit/core';
2024-09-08 10:24:48 -05:00
import { normalizeIds } from './normalizeIds';
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,
'clans/accountinfo',
{
account_id: normalizeIds(ids),
extra: extra.length === 0 ? undefined : extra.join(','),
},
2023-10-12 13:00:33 -05:00
);
if (typeof ids === 'number') {
return object[ids as number] as ReturnType;
} else {
return ids.map((id) => object[id]) as ReturnType;
}
}