mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-18 19:36:13 +01:00
feat: searchplayers
This commit is contained in:
1 parent
a9ba84e5d1
commit
8569079af9
12 files changed
+110
-91
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
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;
|
||||
|
||||
getWargamingResponse<Players>(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}&limit=${limit}`,
|
||||
interaction,
|
||||
(players) => {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(SKILLED_COLOR)
|
||||
.setTitle(`Player search results for "${name}"`)
|
||||
.setDescription(
|
||||
`\`\`\`${
|
||||
players.length === 0
|
||||
? 'No players found.'
|
||||
: players.map((player) => player.nickname).join('\n')
|
||||
}\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
Reference in new issue
Block a user