From af6bdd4da87d3b1b15cee52cfa5271ea2041da56 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 5 Sep 2023 13:36:31 +0200 Subject: [PATCH] WIP add support for filters other than ffmpeg --- src/classes/interactions.ts | 7 +-- src/interactions/commands/player/filters.ts | 48 ++++++++++++++++++++- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/classes/interactions.ts b/src/classes/interactions.ts index fd49810..dce385e 100644 --- a/src/classes/interactions.ts +++ b/src/classes/interactions.ts @@ -6,7 +6,8 @@ import { Interaction, Message, MessageComponentInteraction, - SlashCommandBuilder + SlashCommandBuilder, + SlashCommandSubcommandsOnlyBuilder } from 'discord.js'; import { Logger } from 'pino'; import loggerModule from '../services/logger'; @@ -43,7 +44,7 @@ abstract class BaseInteraction { } export abstract class BaseSlashCommandInteraction extends BaseInteraction { - data: Omit; + data: Omit | SlashCommandSubcommandsOnlyBuilder; isSystemCommand: boolean; isNew: boolean; isBeta: boolean; @@ -52,7 +53,7 @@ export abstract class BaseSlashCommandInteraction extends BaseInteraction { name: string; constructor( - data: Omit, + data: Omit | SlashCommandSubcommandsOnlyBuilder, isSystemCommand: boolean = false, isNew: boolean = false, isBeta: boolean = false diff --git a/src/interactions/commands/player/filters.ts b/src/interactions/commands/player/filters.ts index 9273003..21ba7f4 100644 --- a/src/interactions/commands/player/filters.ts +++ b/src/interactions/commands/player/filters.ts @@ -7,15 +7,17 @@ import { APIStringSelectComponent, ButtonBuilder, ButtonStyle, + ChatInputCommandInteraction, ComponentType, EmbedBuilder, SlashCommandBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } from 'discord.js'; +import { Logger } from 'pino'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { FFmpegFilterOption, FFmpegFilterOptions } from '../../../types/configTypes'; import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; import { queueDoesNotExist, queueNoCurrentTrack } from '../../../utils/validation/queueValidator'; import { notInSameVoiceChannel, notInVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; @@ -23,7 +25,22 @@ const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions class FiltersCommand extends BaseSlashCommandInteraction { constructor() { - const data = new SlashCommandBuilder().setName('filters').setDescription('Toggle various audio filters.'); + const data = new SlashCommandBuilder() + .setName('filters') + .setDescription('Toggle various audio filters.') + .addStringOption((option) => + option + .setName('type') + .setDescription('Audio filtering type to use.') + .setRequired(false) + .addChoices( + { name: 'FFmpeg', value: 'ffmpeg' }, + { name: 'Biquad', value: 'biquad' }, + { name: 'Equalizer', value: 'equalizer' }, + { name: 'Disable', value: 'disable' } + ) + ); + super(data); } @@ -46,6 +63,33 @@ class FiltersCommand extends BaseSlashCommandInteraction { } } + const filterProvider: string = interaction.options.getString('type') || 'ffmpeg'; + + switch (filterProvider) { + case 'ffmpeg': + logger.info('Handling ffmpeg filters.'); + return await this.handleFfmpegFilters(queue, logger, interaction); + case 'biquad': + logger.info('Biquad filters are not yet implemented.'); + break; + case 'equalizer': + logger.info('Equalizer filters are not yet implemented.'); + break; + case 'disable': + logger.info('Disabling filters.'); + if (queue.filters.ffmpeg.filters.length > 0) { + queue.filters.ffmpeg.setFilters(false); + logger.debug('Reset queue filters.'); + } + logger.info('Response not yet implemented.'); + } + } + + private async handleFfmpegFilters( + queue: GuildQueue, + logger: Logger, + interaction: ChatInputCommandInteraction + ) { const filterOptions: StringSelectMenuOptionBuilder[] = []; ffmpegFilterOptions.availableFilters.forEach((filter: FFmpegFilterOption) => {