Files
blitzkit/src/commands/searchtanks.ts
T

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-05-20 00:57:41 +00:00
import { SlashCommandBuilder } from 'discord.js';
import { go } from 'fuzzysort';
import markdownEscape from 'markdown-escape';
2023-05-30 18:42:34 +00:00
import { TANK_NAMES } from '../core/blitz/tankopedia.js';
2023-05-20 00:57:41 +00:00
import cmdName from '../core/interaction/cmdName.js';
2023-05-21 16:50:05 +00:00
import infoEmbed from '../core/interaction/infoEmbed.js';
2023-05-20 00:57:41 +00:00
import addTankChoices from '../core/options/addTankChoices.js';
import { CommandRegistry } from '../events/interactionCreate.js';
export default {
inProduction: true,
2023-06-06 16:53:13 +00:00
inDevelopment: false,
2023-05-20 00:57:41 +00:00
inPublic: true,
command: new SlashCommandBuilder()
.setName(cmdName('searchtanks'))
.setDescription('Search tanks')
.addStringOption((option) => addTankChoices(option).setAutocomplete(false))
.addIntegerOption((option) =>
option
.setName('limit')
.setDescription('The size of the search result (default: 25)')
.setMinValue(1)
.setMaxValue(100),
),
async execute(interaction) {
const tank = interaction.options.getString('tank')!;
const limit = interaction.options.getInteger('limit') ?? 25;
2023-05-30 18:42:34 +00:00
const results = go(tank, TANK_NAMES, { limit }).map(
2023-05-20 00:57:41 +00:00
(result) => result.target,
);
await interaction.editReply({
embeds: [
2023-05-21 16:50:05 +00:00
infoEmbed(
2023-05-20 01:37:18 +00:00
`Tank search for "${markdownEscape(tank)}"`,
2023-05-20 00:57:41 +00:00
results.length === 0
? 'No tanks found.'
: `\`\`\`\n${results.join('\n')}\n\`\`\``,
),
],
});
},
} satisfies CommandRegistry;