mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
27 lines
929 B
TypeScript
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.`,
|
|
);
|
|
}
|
|
}
|
|
}
|