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 { SKILLED_COLOR } from '../constants/colors.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
|
|
|
|
import cmdName from '../core/interaction/cmdName.js';
|
|
|
|
|
import addServerChoices from '../core/options/addServerChoices.js';
|
2023-05-14 17:13:42 +00:00
|
|
|
import addUsernameOption from '../core/options/addUsernameOption.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
import { args } from '../core/process/args.js';
|
2023-05-19 23:50:24 +00:00
|
|
|
import { CommandRegistry } from '../events/interactionCreate.js';
|
2023-05-16 02:02:50 +00:00
|
|
|
import { AccountList } from '../types/accountList.js';
|
2023-05-02 23:01:54 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
inProduction: true,
|
2023-05-20 00:57:41 +00:00
|
|
|
inDevelopment: false,
|
2023-05-02 23:01:54 +00:00
|
|
|
inPublic: true,
|
|
|
|
|
|
|
|
|
|
command: new SlashCommandBuilder()
|
2023-05-13 01:27:12 +00:00
|
|
|
.setName(cmdName('searchplayers'))
|
2023-05-02 23:01:54 +00:00
|
|
|
.setDescription('Search players in a Blitz server')
|
2023-05-10 20:00:30 +00:00
|
|
|
.addStringOption(addServerChoices)
|
2023-05-14 17:13:42 +00:00
|
|
|
.addStringOption((option) =>
|
|
|
|
|
addUsernameOption(option).setAutocomplete(false),
|
|
|
|
|
)
|
2023-05-02 23:01:54 +00:00
|
|
|
.addIntegerOption((option) =>
|
|
|
|
|
option
|
|
|
|
|
.setName('limit')
|
|
|
|
|
.setDescription('The size of the search result (default: 25)')
|
|
|
|
|
.setMinValue(1)
|
|
|
|
|
.setMaxValue(100),
|
|
|
|
|
),
|
|
|
|
|
|
2023-05-08 01:45:57 +00:00
|
|
|
async execute(interaction) {
|
2023-05-02 23:01:54 +00:00
|
|
|
const server = interaction.options.getString('server')!;
|
2023-05-14 17:13:42 +00:00
|
|
|
const name = interaction.options.getString('username')!;
|
2023-05-02 23:01:54 +00:00
|
|
|
const limit = interaction.options.getInteger('limit') ?? 25;
|
2023-05-14 17:13:42 +00:00
|
|
|
const players = await getWargamingResponse<AccountList>(
|
2023-05-02 23:01:54 +00:00
|
|
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}&limit=${limit}`,
|
|
|
|
|
);
|
2023-05-13 22:01:58 +00:00
|
|
|
if (!players) return;
|
2023-05-08 01:45:57 +00:00
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [
|
|
|
|
|
new EmbedBuilder()
|
|
|
|
|
.setColor(SKILLED_COLOR)
|
|
|
|
|
.setTitle(`Player search results for "${markdownEscape(name)}"`)
|
|
|
|
|
.setDescription(
|
|
|
|
|
`\`\`\`${
|
|
|
|
|
players.length === 0
|
|
|
|
|
? 'No players found.'
|
2023-05-16 02:02:50 +00:00
|
|
|
: players.map((player) => player.nickname).join('\n')
|
2023-05-08 01:45:57 +00:00
|
|
|
}\`\`\``,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
});
|
2023-05-20 00:57:41 +00:00
|
|
|
|
|
|
|
|
console.log(`Player search results for "${name}"`);
|
2023-05-02 23:01:54 +00:00
|
|
|
},
|
|
|
|
|
} satisfies CommandRegistry;
|