mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 06:28:53 +00:00
Localization support
This commit is contained in:
12 files changed
+220
-34
No files matched your search
@@ -3,6 +3,8 @@ import { ApplicationCommandOptionChoiceData } from 'discord.js';
|
||||
import { BaseAutocompleteInteraction } from '../../classes/interactions';
|
||||
import { getTrackName, isQueryTooShort, shouldUseLastQuery } from '../../common/autocompleteUtils';
|
||||
import { BaseAutocompleteParams, BaseAutocompleteReturnType, RecentQuery } from '../../types/interactionTypes';
|
||||
import { TFunction } from 'i18next';
|
||||
import { useUserTranslator } from '../../common/localeUtil';
|
||||
|
||||
class PlayAutocomplete extends BaseAutocompleteInteraction {
|
||||
private recentQueries = new Map<string, RecentQuery>();
|
||||
@@ -14,6 +16,7 @@ class PlayAutocomplete extends BaseAutocompleteInteraction {
|
||||
async execute(params: BaseAutocompleteParams): BaseAutocompleteReturnType {
|
||||
const { executionId, interaction } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
const translator = useUserTranslator(interaction);
|
||||
|
||||
const query: string = interaction.options.getString('query', true);
|
||||
|
||||
@@ -29,8 +32,10 @@ class PlayAutocomplete extends BaseAutocompleteInteraction {
|
||||
return interaction.respond([]);
|
||||
}
|
||||
|
||||
const autocompleteChoices: ApplicationCommandOptionChoiceData<string>[] =
|
||||
await this.getAutocompleteChoices(query);
|
||||
const autocompleteChoices: ApplicationCommandOptionChoiceData<string>[] = await this.getAutocompleteChoices(
|
||||
query,
|
||||
translator
|
||||
);
|
||||
|
||||
if (!autocompleteChoices || autocompleteChoices.length === 0) {
|
||||
logger.debug(`Responding with empty results for query '${query}'`);
|
||||
@@ -43,11 +48,14 @@ class PlayAutocomplete extends BaseAutocompleteInteraction {
|
||||
return interaction.respond(autocompleteChoices);
|
||||
}
|
||||
|
||||
private async getAutocompleteChoices(query: string): Promise<ApplicationCommandOptionChoiceData<string>[]> {
|
||||
private async getAutocompleteChoices(
|
||||
query: string,
|
||||
translator: TFunction
|
||||
): Promise<ApplicationCommandOptionChoiceData<string>[]> {
|
||||
const player: Player = useMainPlayer()!;
|
||||
const searchResults: SearchResult = await player.search(query);
|
||||
return searchResults.tracks.slice(0, 5).map((track) => ({
|
||||
name: getTrackName(track),
|
||||
name: getTrackName(track, translator),
|
||||
value: track.url
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user