Files
blitzkit/src/commands/searchplayers.ts
T

59 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-05-02 23:01:54 +00:00
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
2023-05-06 17:45:43 +00:00
import markdownEscape from 'markdown-escape';
2023-05-02 23:01:54 +00:00
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { Players } from '../types/players.js';
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
import { args } from '../utilities/args.js';
import getWargamingResponse from '../utilities/getWargamingResponse.js';
export default {
inDevelopment: false,
inProduction: true,
inPublic: true,
command: new SlashCommandBuilder()
.setName('searchplayers')
.setDescription('Search players in a Blitz server')
.addStringOption(addServerChoices)
.addStringOption(addIGNOption)
.addIntegerOption((option) =>
option
.setName('limit')
.setDescription('The size of the search result (default: 25)')
.setMinValue(1)
.setMaxValue(100),
),
execute(interaction) {
const server = interaction.options.getString('server')!;
const name = interaction.options.getString('name')!;
const limit = interaction.options.getInteger('limit') ?? 25;
2023-05-06 18:03:37 +00:00
const command = `searchplayers ${server} ${name} ${limit}`;
2023-05-02 23:01:54 +00:00
getWargamingResponse<Players>(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}&limit=${limit}`,
interaction,
2023-05-06 18:03:37 +00:00
command,
2023-05-02 23:01:54 +00:00
(players) => {
interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(SKILLED_COLOR)
2023-05-06 17:45:43 +00:00
.setTitle(`Player search results for "${markdownEscape(name)}"`)
2023-05-02 23:01:54 +00:00
.setDescription(
`\`\`\`${
players.length === 0
? 'No players found.'
2023-05-06 17:45:43 +00:00
: players
.map((player) => markdownEscape(player.nickname))
.join('\n')
2023-05-02 23:01:54 +00:00
}\`\`\``,
),
],
});
},
);
},
} satisfies CommandRegistry;