2023-05-28 16:56:15 +00:00
|
|
|
import { SlashCommandBuilder } from 'discord.js';
|
2023-05-06 17:45:43 +00:00
|
|
|
import markdownEscape from 'markdown-escape';
|
2023-05-20 01:37:18 +00:00
|
|
|
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
|
|
|
|
import cmdName from '../core/interaction/cmdName.js';
|
2023-05-28 16:56:15 +00:00
|
|
|
import infoEmbed from '../core/interaction/infoEmbed.js';
|
2023-05-13 22:01:58 +00:00
|
|
|
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-28 17:03:12 +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-20 01:37:18 +00:00
|
|
|
const server = interaction.options.getString('server') as BlitzServer;
|
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-28 16:56:15 +00:00
|
|
|
const normalizedSearch = encodeURIComponent(name.trim());
|
|
|
|
|
const players =
|
|
|
|
|
normalizedSearch.length >= 3 && normalizedSearch.length <= 100
|
|
|
|
|
? await getWargamingResponse<AccountList>(
|
|
|
|
|
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${normalizedSearch}&limit=${limit}`,
|
|
|
|
|
)
|
|
|
|
|
: [];
|
2023-05-08 01:45:57 +00:00
|
|
|
|
|
|
|
|
await interaction.editReply({
|
|
|
|
|
embeds: [
|
2023-05-28 16:56:15 +00:00
|
|
|
infoEmbed(
|
|
|
|
|
`Player search for "${markdownEscape(name)}" in ${
|
|
|
|
|
BLITZ_SERVERS[server]
|
|
|
|
|
}`,
|
|
|
|
|
`\`\`\`${
|
|
|
|
|
players.length === 0
|
|
|
|
|
? 'No players found.'
|
|
|
|
|
: 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;
|