mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
23 lines
772 B
TypeScript
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.`,
|
|
);
|
|
}
|
|
}
|
|
}
|