Files
blitzkit/src/core/discord/resolveClanFromCommand.ts
T

26 lines
967 B
TypeScript
Raw Normal View History

2023-09-07 03:24:07 +00:00
import { ChatInputCommandInteraction } from 'discord.js';
import { Region } from '../../constants/regions';
2023-10-14 11:36:10 -05:00
import searchClansAcrossRegions from '../blitz/searchClansAcrossRegions';
2023-10-17 20:58:36 -05:00
import { UserError } from '../blitzkrieg/userError';
2023-09-07 03:24:07 +00:00
import { serverAndIdPattern } from './resolvePlayerFromCommand';
export default async function resolveClanFromCommand(
interaction: ChatInputCommandInteraction,
) {
const clan = interaction.options.getString('clan', true);
if (serverAndIdPattern.test(clan)) {
const [server, accountId] = clan.split('/');
return { region: server as Region, id: Number(accountId) };
} else {
2023-10-14 11:15:42 -05:00
const accounts = await searchClansAcrossRegions(clan);
2023-09-07 03:24:07 +00:00
if (accounts[0]) {
return { region: accounts[0].region, id: accounts[0].clan_id };
} else {
2023-10-17 20:58:36 -05:00
throw new UserError('Could not find clan', {
cause: `I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`,
});
2023-09-07 03:24:07 +00:00
}
}
}