From c45b80c40ec5a5ae2ad87760d31aeba26d326cde Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 20 May 2023 00:57:41 +0000 Subject: [PATCH] feat: searchtanks --- src/commands/playerachievements.ts | 2 +- src/commands/searchplayers.ts | 4 ++- src/commands/searchtanks.ts | 47 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/commands/searchtanks.ts diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index 6969c56d0..bcc14e126 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -17,7 +17,7 @@ type SortBy = 'name' | 'count'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 3d44364f6..c957788f8 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -10,8 +10,8 @@ import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountList } from '../types/accountList.js'; export default { - inDevelopment: false, inProduction: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() @@ -52,5 +52,7 @@ export default { ), ], }); + + console.log(`Player search results for "${name}"`); }, } satisfies CommandRegistry; diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts new file mode 100644 index 000000000..610c2d865 --- /dev/null +++ b/src/commands/searchtanks.ts @@ -0,0 +1,47 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { go } from 'fuzzysort'; +import markdownEscape from 'markdown-escape'; +import { tankNames } from '../core/blitzstars/tankopedia.js'; +import cmdName from '../core/interaction/cmdName.js'; +import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import addTankChoices from '../core/options/addTankChoices.js'; +import { CommandRegistry } from '../events/interactionCreate.js'; + +export default { + inProduction: true, + inDevelopment: false, + 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; + const results = go(tank, tankNames, { limit }).map( + (result) => result.target, + ); + + await interaction.editReply({ + embeds: [ + sklldEmbed( + `Tank search results for "${markdownEscape(tank)}"`, + results.length === 0 + ? 'No tanks found.' + : `\`\`\`\n${results.join('\n')}\n\`\`\``, + ), + ], + }); + + console.log(`Tank search results for "${tank}"`); + }, +} satisfies CommandRegistry;