feat: lenient username and clan lookup

This commit is contained in:
TresAbhi committed 2023-05-16 02:02:50 +00:00
1 parent 9df4d52bb5
commit 9a9ea3a71a
19 files changed
+292 -209

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
import { BlitzServer } from '../../constants/servers.js';
import { Clan, ClanList } from '../../types/clanList.js';
import { args } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export type ClanListWithServer = (Clan & {
server: 'com' | 'eu' | 'asia';
})[];
export default function listClansPanServer(search: string, limit = 9) {
return new Promise<ClanListWithServer>(async (resolve) => {
const trimmed = search.trim();
if (trimmed.length < 3 && trimmed.length > 100) resolve([]);
const normalizedLimit = Math.round(limit / 3);
const accountList: ClanListWithServer = [];
let done = 0;
function afterResponse() {
done++;
if (done === 3) {
resolve(accountList);
}
}
getWargamingResponse<ClanList>(
`https://api.wotblitz.com/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
).then((value) => {
if (value)
accountList.push(
...value.map((account) => ({
...account,
server: 'com' as BlitzServer,
})),
);
afterResponse();
});
getWargamingResponse<ClanList>(
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
).then((value) => {
if (value)
accountList.push(
...value.map((account) => ({
...account,
server: 'eu' as BlitzServer,
})),
);
afterResponse();
});
getWargamingResponse<ClanList>(
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
).then((value) => {
if (value)
accountList.push(
...value.map((account) => ({
...account,
server: 'asia' as BlitzServer,
})),
);
afterResponse();
});
});
}