feat: searchtanks

This commit is contained in:
TresAbhi committed 2023-05-20 00:57:41 +00:00
1 parent d3c515b30f
commit c45b80c40e
3 files changed
+51 -2

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ type SortBy = 'name' | 'count';
export default {
inProduction: true,
inDevelopment: true,
inDevelopment: false,
inPublic: true,
command: new SlashCommandBuilder()
+3 -1
View File
@@ -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;
+47
View File
@@ -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;