mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-14 05:06:11 +01:00
feat: username suggestions
This commit is contained in:
1 parent
613527e78f
commit
692f4d2b80
13 files changed
+167
-102
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
ApplicationCommandOptionChoiceData,
|
||||
AutocompleteInteraction,
|
||||
CacheType,
|
||||
} from 'discord.js';
|
||||
import { BlitzServer } from '../../constants/servers.js';
|
||||
import { AccountList } from '../../types/players.js';
|
||||
import getWargamingResponse from '../blitz/getWargamingResponse.js';
|
||||
import { args } from '../process/args.js';
|
||||
|
||||
export default async function usernameAutocomplete(
|
||||
interaction: AutocompleteInteraction<CacheType>,
|
||||
) {
|
||||
const focusedOption = interaction.options.getFocused(true);
|
||||
if (focusedOption.name !== 'username') return;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
|
||||
const players = await getWargamingResponse<AccountList>(
|
||||
`https://api.wotblitz.${
|
||||
server ?? 'com'
|
||||
}/wotb/account/list/?application_id=${
|
||||
args['wargaming-application-id']
|
||||
}&search=${focusedOption.value}&limit=10`,
|
||||
);
|
||||
|
||||
await interaction.respond(
|
||||
players
|
||||
? players.map(
|
||||
(player) =>
|
||||
({
|
||||
name: player.nickname,
|
||||
value: `${player.account_id}`,
|
||||
} satisfies ApplicationCommandOptionChoiceData<string>),
|
||||
)
|
||||
: [],
|
||||
);
|
||||
|
||||
console.log(`Username autocomplete for ${focusedOption.value}`);
|
||||
}
|
||||
Reference in new issue
Block a user