mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
feat: add biquad filters support
This commit is contained in:
1 parent
7dc7b4ff7e
commit
0b94a9b5ec
5 files changed
+326
-77
No files matched your search
@@ -209,6 +209,71 @@ module.exports.ffmpegFilterOptions = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.biquadFilterOptions = {
|
||||||
|
availableFilters: [
|
||||||
|
{
|
||||||
|
label: 'Basic Low Pass (Approx.)',
|
||||||
|
value: 'SinglePoleLowPassApprox',
|
||||||
|
description: 'Low frequencies pass, approximate.',
|
||||||
|
emoji: '🔉'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Basic Low Pass',
|
||||||
|
value: 'SinglePoleLowPass',
|
||||||
|
description: 'Low frequencies pass.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Advanced Low Pass',
|
||||||
|
value: 'LowPass',
|
||||||
|
description: 'Enhanced low frequency pass.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'High Pass',
|
||||||
|
value: 'HighPass',
|
||||||
|
description: 'High frequencies pass.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Band Pass',
|
||||||
|
value: 'BandPass',
|
||||||
|
description: 'Specific frequency range pass.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Notch Filter',
|
||||||
|
value: 'Notch',
|
||||||
|
description: 'Reduces specific frequency.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Phase Adjuster',
|
||||||
|
value: 'AllPass',
|
||||||
|
description: 'Alters sound phase.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Low Shelf',
|
||||||
|
value: 'LowShelf',
|
||||||
|
description: 'Boosts/reduces low frequencies.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'High Shelf',
|
||||||
|
value: 'HighShelf',
|
||||||
|
description: 'Boosts/reduces high frequencies.',
|
||||||
|
emoji: '🔊'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Peaking Equalizer',
|
||||||
|
value: 'PeakingEQ',
|
||||||
|
description: 'Adjusts specific frequencies.',
|
||||||
|
emoji: '🔊'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
// Configuration for load testing. Enables the bot to simulate certain behaviors for testing purposes.
|
// Configuration for load testing. Enables the bot to simulate certain behaviors for testing purposes.
|
||||||
// If enabled, the bot will join the specified channels and play specified track.
|
// If enabled, the bot will join the specified channels and play specified track.
|
||||||
module.exports.loadTestOptions = {
|
module.exports.loadTestOptions = {
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { Logger } from 'pino';
|
import { Logger } from 'pino';
|
||||||
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
|
||||||
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes';
|
import { BiquadFilterOptions, FFmpegFilterOptions, FilterOption } from '../../../types/configTypes';
|
||||||
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';
|
||||||
|
|
||||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||||
|
const biquadFilterOptions: BiquadFilterOptions = config.get('biquadFilterOptions');
|
||||||
|
|
||||||
class FiltersCommand extends BaseSlashCommandInteraction {
|
class FiltersCommand extends BaseSlashCommandInteraction {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -32,13 +33,13 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('type')
|
.setName('type')
|
||||||
.setDescription('Audio filtering type to use.')
|
.setDescription('Audio filter type to use.')
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
.addChoices(
|
.addChoices(
|
||||||
{ name: 'FFmpeg', value: 'FFmpeg' },
|
{ name: 'FFmpeg', value: 'ffmpeg' },
|
||||||
{ name: 'Biquad', value: 'Biquad' },
|
{ name: 'Biquad', value: 'biquad' },
|
||||||
{ name: 'Equalizer', value: 'Equalizer' },
|
{ name: 'Equalizer', value: 'equalizer' },
|
||||||
{ name: 'Disable', value: 'Disable' }
|
{ name: 'Disable', value: 'disable' }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
super(data);
|
super(data);
|
||||||
@@ -57,21 +58,19 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
checkQueueCurrentTrack
|
checkQueueCurrentTrack
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const filterProvider: string = interaction.options.getString('type') || 'FFmpeg';
|
const filterProvider: string = interaction.options.getString('type') || 'ffmpeg';
|
||||||
|
|
||||||
switch (filterProvider.toLowerCase()) {
|
switch (filterProvider) {
|
||||||
case 'ffmpeg':
|
case 'ffmpeg':
|
||||||
logger.debug('Handling ffmpeg filters.');
|
|
||||||
return await this.handleFfmpegFilters(logger, interaction, queue);
|
return await this.handleFfmpegFilters(logger, interaction, queue);
|
||||||
case 'biquad':
|
case 'biquad':
|
||||||
logger.debug('Handling biquad filters.');
|
return await this.handleBiquadFilters(logger, interaction, queue);
|
||||||
return await this.tempNotImplementedResponse(logger, interaction);
|
|
||||||
case 'equalizer':
|
case 'equalizer':
|
||||||
|
// TODO: implement
|
||||||
logger.debug('Handling equalizer filters.');
|
logger.debug('Handling equalizer filters.');
|
||||||
return await this.tempNotImplementedResponse(logger, interaction);
|
return await this.tempNotImplementedResponse(logger, interaction);
|
||||||
case 'disable':
|
case 'disable':
|
||||||
logger.debug('Disabling filters.');
|
return await this.disableAllFiltersAndRespondWithSuccess(logger, interaction, queue);
|
||||||
return await this.tempDisableFilters(logger, interaction, queue);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,9 +79,10 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
queue: GuildQueue<unknown>
|
queue: GuildQueue<unknown>
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
|
logger.debug('Handling ffmpeg filters.');
|
||||||
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||||
|
|
||||||
ffmpegFilterOptions.availableFilters.forEach((filter: FFmpegFilterOption) => {
|
ffmpegFilterOptions.availableFilters.forEach((filter: FilterOption) => {
|
||||||
let isEnabled: boolean = false;
|
let isEnabled: boolean = false;
|
||||||
|
|
||||||
if (queue.filters.ffmpeg.filters.includes(filter.value as keyof QueueFilters)) {
|
if (queue.filters.ffmpeg.filters.includes(filter.value as keyof QueueFilters)) {
|
||||||
@@ -99,11 +99,69 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return await this.sendFiltersEmbed(logger, interaction, 'ffmpeg', filterOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleBiquadFilters(
|
||||||
|
logger: Logger,
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
queue: GuildQueue<unknown>
|
||||||
|
): Promise<Message> {
|
||||||
|
logger.debug('Handling biquad filters.');
|
||||||
|
const filterOptions: StringSelectMenuOptionBuilder[] = [];
|
||||||
|
|
||||||
|
biquadFilterOptions.availableFilters.forEach((filter: FilterOption) => {
|
||||||
|
let isEnabled: boolean = false;
|
||||||
|
if (queue.filters.biquad!.biquadFilter === (filter.value as keyof BiquadFilterType)) {
|
||||||
|
isEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
filterOptions.push(
|
||||||
|
new StringSelectMenuOptionBuilder()
|
||||||
|
.setLabel(filter.label)
|
||||||
|
.setDescription(filter.description)
|
||||||
|
.setValue(filter.value)
|
||||||
|
.setEmoji(filter.emoji)
|
||||||
|
.setDefault(isEnabled)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return await this.sendFiltersEmbed(logger, interaction, 'biquad', filterOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async sendFiltersEmbed(
|
||||||
|
logger: Logger,
|
||||||
|
interaction: ChatInputCommandInteraction,
|
||||||
|
filterProvider: string,
|
||||||
|
filterOptions: StringSelectMenuOptionBuilder[]
|
||||||
|
): Promise<Message> {
|
||||||
|
const actionRows = this.buildFilterActionRows(filterOptions, filterProvider);
|
||||||
|
|
||||||
|
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.'
|
||||||
|
)
|
||||||
|
.setColor(this.embedOptions.colors.info)
|
||||||
|
],
|
||||||
|
components: actionRows
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildFilterActionRows(
|
||||||
|
filterOptions: StringSelectMenuOptionBuilder[],
|
||||||
|
filterProvider: string
|
||||||
|
): APIActionRowComponent<APIMessageActionRowComponent>[] {
|
||||||
const filterSelect: APIStringSelectComponent = new StringSelectMenuBuilder()
|
const filterSelect: APIStringSelectComponent = new StringSelectMenuBuilder()
|
||||||
.setCustomId('filters-select-menu')
|
.setCustomId(`filters-select-menu_${filterProvider}`)
|
||||||
.setPlaceholder('Select multiple options.')
|
.setPlaceholder(
|
||||||
|
filterProvider === 'ffmpeg' ? 'Select one or multiple filters.' : 'Select a filter from the menu.'
|
||||||
|
)
|
||||||
.setMinValues(0)
|
.setMinValues(0)
|
||||||
.setMaxValues(filterOptions.length)
|
.setMaxValues(1)
|
||||||
.addOptions(filterOptions)
|
.addOptions(filterOptions)
|
||||||
.toJSON();
|
.toJSON();
|
||||||
|
|
||||||
@@ -124,29 +182,28 @@ class FiltersCommand extends BaseSlashCommandInteraction {
|
|||||||
components: [disableButton]
|
components: [disableButton]
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.debug('Sending info embed with action row components.');
|
return [filterActionRow, disableFiltersActionRow];
|
||||||
return await interaction.editReply({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
|
||||||
.setDescription(
|
|
||||||
'**Toggle filters**\n' + 'Enable or disable audio filters for playback from the menu.'
|
|
||||||
)
|
|
||||||
.setColor(this.embedOptions.colors.info)
|
|
||||||
],
|
|
||||||
components: [filterActionRow, disableFiltersActionRow]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async tempDisableFilters(
|
private async disableAllFiltersAndRespondWithSuccess(
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
interaction: ChatInputCommandInteraction,
|
interaction: ChatInputCommandInteraction,
|
||||||
queue: GuildQueue
|
queue: GuildQueue
|
||||||
): 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);
|
||||||
logger.debug('Reset queue filters.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queue.filters.biquad) {
|
||||||
|
queue.filters.biquad.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.filters.equalizer) {
|
||||||
|
queue.filters.equalizer.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug('Reset queue filters.');
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ class FiltersDisableButtonComponent extends BaseComponentInteraction {
|
|||||||
queue.filters.ffmpeg.setFilters(false);
|
queue.filters.ffmpeg.setFilters(false);
|
||||||
logger.debug('Reset queue filters.');
|
logger.debug('Reset queue filters.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (queue.filters.biquad) {
|
||||||
|
queue.filters.biquad.disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { GuildQueue, QueueFilters, useQueue } from 'discord-player';
|
import { BiquadFilters, GuildQueue, QueueFilters, useQueue } from 'discord-player';
|
||||||
import { EmbedBuilder, StringSelectMenuInteraction } from 'discord.js';
|
import { EmbedBuilder, Message, StringSelectMenuInteraction } from 'discord.js';
|
||||||
|
import { Logger } from 'pino';
|
||||||
import { BaseComponentInteraction } from '../../classes/interactions';
|
import { BaseComponentInteraction } from '../../classes/interactions';
|
||||||
import { FFmpegFilterOption, FFmpegFilterOptions } from '../../types/configTypes';
|
import { BiquadFilterOptions, FFmpegFilterOptions, FilterOption } from '../../types/configTypes';
|
||||||
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
||||||
import { checkQueueExists } from '../../utils/validation/queueValidator';
|
import { checkQueueExists } from '../../utils/validation/queueValidator';
|
||||||
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../utils/validation/voiceChannelValidator';
|
||||||
import { Logger } from 'pino';
|
|
||||||
|
|
||||||
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
|
||||||
|
const biquadFilterOptions: BiquadFilterOptions = config.get('biquadFilterOptions');
|
||||||
|
|
||||||
class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -16,10 +17,11 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async execute(params: BaseComponentParams): BaseComponentReturnType {
|
async execute(params: BaseComponentParams): BaseComponentReturnType {
|
||||||
const { executionId, interaction } = params;
|
const { executionId, interaction, referenceId } = params;
|
||||||
const logger = this.getLogger(this.name, executionId, interaction);
|
const logger = this.getLogger(this.name, executionId, interaction);
|
||||||
|
const filterType = referenceId;
|
||||||
|
|
||||||
logger.debug('Received select menu confirmation.');
|
logger.debug('Received select menu interaction.');
|
||||||
|
|
||||||
const selectMenuInteraction: StringSelectMenuInteraction = interaction as StringSelectMenuInteraction;
|
const selectMenuInteraction: StringSelectMenuInteraction = interaction as StringSelectMenuInteraction;
|
||||||
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
const queue: GuildQueue = useQueue(interaction.guild!.id)!;
|
||||||
@@ -31,24 +33,156 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
this.resetFilters(queue, logger);
|
this.resetFilters(queue, logger);
|
||||||
this.enableNormalizerIfRequired(selectMenuInteraction);
|
|
||||||
this.enableProvidedFilters(selectMenuInteraction, queue, logger);
|
if (selectMenuInteraction.values.length === 0) {
|
||||||
|
return await this.replyWithDisabledFiltersEmbed(logger, selectMenuInteraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (filterType) {
|
||||||
|
case 'ffmpeg':
|
||||||
|
return await this.handleFfmpegFilterToggle(logger, selectMenuInteraction, queue, filterType);
|
||||||
|
case 'biquad':
|
||||||
|
return await this.handleBiquadFilterToggle(logger, selectMenuInteraction, queue, filterType);
|
||||||
|
case 'equalizer':
|
||||||
|
// TODO: implement
|
||||||
|
logger.info('equalizer');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
logger.warn(`Unknown filter type '${filterType}'.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleFfmpegFilterToggle(
|
||||||
|
logger: Logger,
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
filterType: string
|
||||||
|
): Promise<Message> {
|
||||||
|
this.addFfmpegNormalizerIfRequired(selectMenuInteraction);
|
||||||
|
this.toggleFfmpegFilters(selectMenuInteraction, queue, logger);
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
logger.debug('Responding with success embed.');
|
||||||
return await selectMenuInteraction.editReply({
|
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
|
||||||
embeds: [this.buildSuccessEmbed(selectMenuInteraction)],
|
}
|
||||||
|
|
||||||
|
private async handleBiquadFilterToggle(
|
||||||
|
logger: Logger,
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
filterType: string
|
||||||
|
): Promise<Message> {
|
||||||
|
this.toggleBiquadFilter(selectMenuInteraction, queue, logger);
|
||||||
|
|
||||||
|
logger.debug('Responding with success embed.');
|
||||||
|
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private toggleFfmpegFilters(
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
logger: Logger
|
||||||
|
): void {
|
||||||
|
try {
|
||||||
|
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
|
||||||
|
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, 'Unhandled error while toggling filters.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private toggleBiquadFilter(
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
logger: Logger
|
||||||
|
): void {
|
||||||
|
try {
|
||||||
|
queue.filters.biquad!.enable();
|
||||||
|
queue.filters.biquad!.setGain(5);
|
||||||
|
queue.filters.biquad!.setFilter(selectMenuInteraction.values[0] as BiquadFilters);
|
||||||
|
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, 'Unhandled error while toggling filters.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private resetFilters(queue: GuildQueue, logger: Logger): void {
|
||||||
|
if (queue.filters.ffmpeg.filters.length > 0) {
|
||||||
|
queue.filters.ffmpeg.setFilters(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.filters.biquad) {
|
||||||
|
queue.filters.biquad.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queue.filters.equalizer) {
|
||||||
|
queue.filters.equalizer.disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug('Reset queue filters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
private sendFiltersToggledSuccessEmbed(
|
||||||
|
logger: Logger,
|
||||||
|
interaction: StringSelectMenuInteraction,
|
||||||
|
filterType: string
|
||||||
|
): Promise<Message> {
|
||||||
|
logger.debug('Responding with success embed.');
|
||||||
|
return interaction.editReply({
|
||||||
|
embeds: [this.buildSuccessEmbed(interaction, filterType)],
|
||||||
components: []
|
components: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private resetFilters(queue: GuildQueue, logger: Logger) {
|
private buildSuccessEmbed(selectMenuInteraction: StringSelectMenuInteraction, filterType: string): EmbedBuilder {
|
||||||
if (queue.filters.ffmpeg.filters.length > 0) {
|
const availableFilters: FilterOption[] = this.getAvailableFilters(filterType);
|
||||||
queue.filters.ffmpeg.setFilters(false);
|
const enabledFilters: string = this.getEnabledFilters(selectMenuInteraction, availableFilters);
|
||||||
logger.debug('Reset queue filters.');
|
|
||||||
}
|
return new EmbedBuilder()
|
||||||
|
.setAuthor(this.getEmbedUserAuthor(selectMenuInteraction))
|
||||||
|
.setDescription(
|
||||||
|
`**${this.embedOptions.icons.success} Filters toggled**\n` +
|
||||||
|
`Now using these ${filterType} filters:\n` +
|
||||||
|
`${enabledFilters}`
|
||||||
|
)
|
||||||
|
.setColor(this.embedOptions.colors.success);
|
||||||
}
|
}
|
||||||
|
|
||||||
private enableNormalizerIfRequired(selectMenuInteraction: StringSelectMenuInteraction) {
|
private getAvailableFilters(filterType: string): FilterOption[] {
|
||||||
|
let availableFilters: FilterOption[] = [];
|
||||||
|
|
||||||
|
switch (filterType) {
|
||||||
|
case 'ffmpeg':
|
||||||
|
availableFilters = ffmpegFilterOptions.availableFilters;
|
||||||
|
break;
|
||||||
|
case 'biquad':
|
||||||
|
availableFilters = biquadFilterOptions.availableFilters;
|
||||||
|
break;
|
||||||
|
case 'equalizer':
|
||||||
|
break; // TODO: implement
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getEnabledFilters(
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
availableFilters: FilterOption[]
|
||||||
|
): string {
|
||||||
|
return selectMenuInteraction.values
|
||||||
|
.map((enabledFilter: string) => {
|
||||||
|
const filter: FilterOption | undefined = availableFilters.find(
|
||||||
|
(filter) => enabledFilter == filter.value
|
||||||
|
);
|
||||||
|
|
||||||
|
return filter ? `- **${filter.emoji} ${filter.label}**` : enabledFilter;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private addFfmpegNormalizerIfRequired(selectMenuInteraction: StringSelectMenuInteraction) {
|
||||||
if (
|
if (
|
||||||
ffmpegFilterOptions.forceNormalizerByBassBoost &&
|
ffmpegFilterOptions.forceNormalizerByBassBoost &&
|
||||||
(selectMenuInteraction.values.includes('bassboost_low') ||
|
(selectMenuInteraction.values.includes('bassboost_low') ||
|
||||||
@@ -59,38 +193,23 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enableProvidedFilters(
|
private async replyWithDisabledFiltersEmbed(
|
||||||
selectMenuInteraction: StringSelectMenuInteraction,
|
logger: Logger,
|
||||||
queue: GuildQueue,
|
interaction: StringSelectMenuInteraction
|
||||||
logger: Logger
|
): Promise<Message> {
|
||||||
) {
|
logger.debug('Responding with success embed.');
|
||||||
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
|
return await interaction.editReply({
|
||||||
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
embeds: [
|
||||||
}
|
new EmbedBuilder()
|
||||||
|
.setAuthor(this.getEmbedUserAuthor(interaction))
|
||||||
private buildSuccessEmbed(selectMenuInteraction: StringSelectMenuInteraction) {
|
|
||||||
const enabledFilters: string = selectMenuInteraction.values
|
|
||||||
.map((enabledFilter: string) => {
|
|
||||||
const filter: FFmpegFilterOption | undefined = ffmpegFilterOptions.availableFilters.find(
|
|
||||||
(filter) => enabledFilter == filter.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!filter) {
|
|
||||||
return enabledFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `- **${filter.emoji} ${filter.label}**`;
|
|
||||||
})
|
|
||||||
.join('\n');
|
|
||||||
|
|
||||||
return new EmbedBuilder()
|
|
||||||
.setAuthor(this.getEmbedUserAuthor(selectMenuInteraction))
|
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`**${this.embedOptions.icons.success} Filters toggled**\n` +
|
`**${this.embedOptions.icons.success} Disabled filters**\n` +
|
||||||
'Now using these filters:\n' +
|
'All audio filters have been disabled.'
|
||||||
`${enabledFilters}`
|
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.success);
|
.setColor(this.embedOptions.colors.success)
|
||||||
|
],
|
||||||
|
components: []
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+5
-1
@@ -107,7 +107,7 @@ export type PlayerOptions = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FFmpegFilterOption = {
|
export type FilterOption = {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -120,6 +120,10 @@ export type FFmpegFilterOptions = {
|
|||||||
availableFilters: FFmpegFilterOption[];
|
availableFilters: FFmpegFilterOption[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type BiquadFilterOptions = {
|
||||||
|
availableFilters: FFmpegFilterOption[];
|
||||||
|
};
|
||||||
|
|
||||||
export type LoadTestOptions = {
|
export type LoadTestOptions = {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
trackUrl: string;
|
trackUrl: string;
|
||||||
|
|||||||
Reference in new issue
Block a user