Files
blitzkit/src/core/blitz/getBlitzClan.ts
T
2023-06-27 01:46:08 +00:00

27 lines
929 B
TypeScript

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