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