Files
blitzkit/src/core/blitz/getBlitzClan.ts
T
2023-06-27 17:22:27 +00:00

23 lines
772 B
TypeScript

import { BlitzServer } from '../../constants/servers.js';
import { serverAndIdPattern } from '../discord/resolvePlayerFromCommand.js';
import throwError from '../node/throwError.js';
import listClans from './listClans.js';
export default async function getBlitzClan(clan: string) {
if (serverAndIdPattern.test(clan)) {
const [server, accountId] = clan.split('/');
return { server: server as BlitzServer, id: Number(accountId) };
} else {
const accounts = await listClans(clan);
if (accounts[0]) {
return { server: accounts[0].server, id: accounts[0].clan_id };
} else {
throw throwError(
'Could not find clan',
`I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`,
);
}
}
}