mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
Filters transcription
This commit is contained in:
3 files changed
+48
-25
No files matched your search
@@ -26,7 +26,8 @@ import {
|
||||
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
|
||||
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
|
||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';
|
||||
import { localizeCommand } from '../../../common/localeUtil';
|
||||
import { localizeCommand, useServerTranslator } from '../../../common/localeUtil';
|
||||
import { TFunction } from 'i18next';
|
||||
|
||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||
const biquadFilterOptions: BiquadFilterOptions = config.get('biquadFilterOptions');
|
||||
@@ -34,6 +35,8 @@ const equalizerFilterOptions: EqualizerFilterOptions = config.get('equalizerFilt
|
||||
|
||||
class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
constructor() {
|
||||
// TODO: Localize choices
|
||||
// TODO: Implement system for localized filter names and descriptions
|
||||
const data = localizeCommand(
|
||||
new SlashCommandBuilder()
|
||||
.setName('filters')
|
||||
@@ -55,6 +58,7 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
|
||||
const { executionId, interaction } = params;
|
||||
const logger = this.getLogger(this.name, executionId, interaction);
|
||||
const translator = useServerTranslator(interaction);
|
||||
|
||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||
|
||||
@@ -69,20 +73,21 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
switch (filterProvider) {
|
||||
case 'ffmpeg':
|
||||
return await this.handleFfmpegFilters(logger, interaction, queue);
|
||||
return await this.handleFfmpegFilters(logger, interaction, queue, translator);
|
||||
case 'biquad':
|
||||
return await this.handleBiquadFilters(logger, interaction, queue);
|
||||
return await this.handleBiquadFilters(logger, interaction, queue, translator);
|
||||
case 'equalizer':
|
||||
return await this.handleEqualizerFilters(logger, interaction);
|
||||
return await this.handleEqualizerFilters(logger, interaction, translator);
|
||||
case 'disable':
|
||||
return await this.disableAllFiltersAndRespondWithSuccess(logger, interaction, queue);
|
||||
return await this.disableAllFiltersAndRespondWithSuccess(logger, interaction, queue, translator);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleFfmpegFilters(
|
||||
logger: Logger,
|
||||
interaction: ChatInputCommandInteraction,
|
||||
queue: GuildQueue<unknown>
|
||||
queue: GuildQueue<unknown>,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
logger.debug('Handling ffmpeg filters.');
|
||||
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||
@@ -104,13 +109,14 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
);
|
||||
});
|
||||
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'ffmpeg', filterOptions);
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'ffmpeg', filterOptions, translator);
|
||||
}
|
||||
|
||||
private async handleBiquadFilters(
|
||||
logger: Logger,
|
||||
interaction: ChatInputCommandInteraction,
|
||||
queue: GuildQueue<unknown>
|
||||
queue: GuildQueue<unknown>,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
logger.debug('Handling biquad filters.');
|
||||
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||
@@ -131,10 +137,14 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
);
|
||||
});
|
||||
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'biquad', filterOptions);
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'biquad', filterOptions, translator);
|
||||
}
|
||||
|
||||
private async handleEqualizerFilters(logger: Logger, interaction: ChatInputCommandInteraction): Promise<Message> {
|
||||
private async handleEqualizerFilters(
|
||||
logger: Logger,
|
||||
interaction: ChatInputCommandInteraction,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
logger.debug('Handling biquad filters.');
|
||||
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||
|
||||
@@ -149,25 +159,23 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
);
|
||||
});
|
||||
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'equalizer', filterOptions);
|
||||
return await this.sendFiltersEmbed(logger, interaction, 'equalizer', filterOptions, translator);
|
||||
}
|
||||
|
||||
private async sendFiltersEmbed(
|
||||
logger: Logger,
|
||||
interaction: ChatInputCommandInteraction,
|
||||
filterProvider: string,
|
||||
filterOptions: StringSelectMenuOptionBuilder[]
|
||||
filterOptions: StringSelectMenuOptionBuilder[],
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
const actionRows = this.buildFilterActionRows(filterOptions, filterProvider);
|
||||
const actionRows = this.buildFilterActionRows(filterOptions, filterProvider, translator);
|
||||
|
||||
logger.debug('Sending info embed with action row components.');
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**Toggle filters (${filterProvider})**\n` +
|
||||
'Enable or disable audio filters for playback from the menu.'
|
||||
)
|
||||
.setDescription(translator('commands.filters.toggleFilterInstructions'))
|
||||
.setColor(this.embedOptions.colors.info)
|
||||
],
|
||||
components: actionRows
|
||||
@@ -176,12 +184,15 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
|
||||
private buildFilterActionRows(
|
||||
filterOptions: StringSelectMenuOptionBuilder[],
|
||||
filterProvider: string
|
||||
filterProvider: string,
|
||||
translator: TFunction
|
||||
): APIActionRowComponent<APIMessageActionRowComponent>[] {
|
||||
const filterSelect: APIStringSelectComponent = new StringSelectMenuBuilder()
|
||||
.setCustomId(`filters-select-menu_${filterProvider}`)
|
||||
.setPlaceholder(
|
||||
filterProvider === 'ffmpeg' ? 'Select one or multiple filters.' : 'Select a filter from the menu.'
|
||||
filterProvider === 'ffmpeg'
|
||||
? translator('commands.filters.selectFilterPlaceholderMany')
|
||||
: translator('commands.filters.selectFilterPlaceholder')
|
||||
)
|
||||
.setMinValues(0)
|
||||
.setMaxValues(1)
|
||||
@@ -200,7 +211,7 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
.toJSON();
|
||||
|
||||
if (this.embedOptions.components.showButtonLabels) {
|
||||
disableButton.label = 'Disable all filters';
|
||||
disableButton.label = translator('commands.filters.disableAllFiltersButton');
|
||||
}
|
||||
|
||||
const disableFiltersActionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
@@ -214,7 +225,8 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
private async disableAllFiltersAndRespondWithSuccess(
|
||||
logger: Logger,
|
||||
interaction: ChatInputCommandInteraction,
|
||||
queue: GuildQueue
|
||||
queue: GuildQueue,
|
||||
translator: TFunction
|
||||
): Promise<Message> {
|
||||
if (queue.filters.ffmpeg.filters.length > 0) {
|
||||
queue.filters.ffmpeg.setFilters(false);
|
||||
@@ -236,8 +248,9 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
||||
new EmbedBuilder()
|
||||
.setAuthor(this.getEmbedUserAuthor(interaction))
|
||||
.setDescription(
|
||||
`**${this.embedOptions.icons.success} Disabled filters**\n` +
|
||||
'All audio filters have been disabled.'
|
||||
translator('commands.filters.allFiltersDisabled', {
|
||||
icon: this.embedOptions.icons.success
|
||||
})
|
||||
)
|
||||
.setColor(this.embedOptions.colors.success)
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user