Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
feat: added equalizer filters to /filters command
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusbegby committed Sep 17, 2023
1 parent ebe20fe commit 9584fe8
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 38 deletions.
139 changes: 129 additions & 10 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,75 +205,194 @@ module.exports.ffmpegFilterOptions = {
value: 'silenceremove',
description: 'Remove silence from start of tracks.',
emoji: '🔇'
},
{
label: 'Fade in',
value: 'fadein',
description: 'Fade in the audio at the start of tracks.',
emoji: '📈'
}
]
};

module.exports.biquadFilterOptions = {
availableFilters: [
{
label: 'Basic Low Pass (Approx.)',
label: 'Basic low pass (approx.)',
value: 'SinglePoleLowPassApprox',
description: 'Low frequencies pass, approximate.',
emoji: '🔉'
},
{
label: 'Basic Low Pass',
label: 'Basic low pass',
value: 'SinglePoleLowPass',
description: 'Low frequencies pass.',
emoji: '🔊'
},
{
label: 'Advanced Low Pass',
label: 'Advanced low pass',
value: 'LowPass',
description: 'Enhanced low frequency pass.',
emoji: '🔊'
},
{
label: 'High Pass',
label: 'High pass',
value: 'HighPass',
description: 'High frequencies pass.',
emoji: '🔊'
},
{
label: 'Band Pass',
label: 'Band pass',
value: 'BandPass',
description: 'Specific frequency range pass.',
emoji: '🔊'
},
{
label: 'Notch Filter',
label: 'Notch filter',
value: 'Notch',
description: 'Reduces specific frequency.',
emoji: '🔊'
},
{
label: 'Phase Adjuster',
label: 'Phase adjuster',
value: 'AllPass',
description: 'Alters sound phase.',
emoji: '🔊'
},
{
label: 'Low Shelf',
label: 'Low shelf',
value: 'LowShelf',
description: 'Boosts/reduces low frequencies.',
emoji: '🔊'
},
{
label: 'High Shelf',
label: 'High shelf',
value: 'HighShelf',
description: 'Boosts/reduces high frequencies.',
emoji: '🔊'
},
{
label: 'Peaking Equalizer',
label: 'Peaking equalizer',
value: 'PeakingEQ',
description: 'Adjusts specific frequencies.',
emoji: '🔊'
}
]
};

module.exports.equalizerFilterOptions = {
availableFilters: [
{
label: 'Flat',
value: 'Flat',
description: 'Neutral sound balance',
emoji: '🔉'
},
{
label: 'Classical',
value: 'Classical',
description: 'Optimized for orchestras',
emoji: '🎻'
},
{
label: 'Club',
value: 'Club',
description: 'Boosted bass and treble',
emoji: '🎵'
},
{
label: 'Dance',
value: 'Dance',
description: 'High bass and treble',
emoji: '💃'
},
{
label: 'Full bass',
value: 'FullBass',
description: 'Maximized bass response',
emoji: '🔊'
},
{
label: 'Full bass & treble',
value: 'FullBassTreble',
description: 'Bass and treble boost',
emoji: '🎵'
},
{
label: 'Full treble',
value: 'FullTreble',
description: 'Maximized treble response',
emoji: '🎶'
},
{
label: 'Headphones',
value: 'Headphones',
description: 'Optimized for headphones',
emoji: '🎧'
},
{
label: 'Large hall',
value: 'LargeHall',
description: 'Echo effect for halls',
emoji: '🏛️'
},
{
label: 'Live',
value: 'Live',
description: 'Imitates live music',
emoji: '🎤'
},
{
label: 'Party',
value: 'Party',
description: 'Balanced for loudness',
emoji: '🎉'
},
{
label: 'Pop',
value: 'Pop',
description: 'Optimized for pop music',
emoji: '🎤'
},
{
label: 'Reggae',
value: 'Reggae',
description: 'Optimized for reggae music',
emoji: '🎷'
},
{
label: 'Rock',
value: 'Rock',
description: 'Optimized for rock music',
emoji: '🎸'
},
{
label: 'Ska',
value: 'Ska',
description: 'Optimized for ska music',
emoji: '🎷'
},
{
label: 'Soft',
value: 'Soft',
description: 'Softened sound balance',
emoji: '🎶'
},
{
label: 'Soft rock',
value: 'SoftRock',
description: 'Optimized for soft rock',
emoji: '🎸'
},
{
label: 'Techno',
value: 'Techno',
description: 'Optimized for techno music',
emoji: '🎹'
}
]
};

// 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.
module.exports.loadTestOptions = {
Expand Down
48 changes: 26 additions & 22 deletions src/interactions/commands/player/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ import {
} from 'discord.js';
import { Logger } from 'pino';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BiquadFilterOptions, FFmpegFilterOptions, FilterOption } from '../../../types/configTypes';
import {
BiquadFilterOptions,
EqualizerFilterOptions,
FFmpegFilterOptions,
FilterOption
} from '../../../types/configTypes';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
import { checkQueueCurrentTrack, checkQueueExists } from '../../../utils/validation/queueValidator';
import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator';

const ffmpegFilterOptions: FFmpegFilterOptions = config.get('ffmpegFilterOptions');
const biquadFilterOptions: BiquadFilterOptions = config.get('biquadFilterOptions');
const equalizerFilterOptions: EqualizerFilterOptions = config.get('equalizerFilterOptions');

class FiltersCommand extends BaseSlashCommandInteraction {
constructor() {
Expand Down Expand Up @@ -66,9 +72,7 @@ class FiltersCommand extends BaseSlashCommandInteraction {
case 'biquad':
return await this.handleBiquadFilters(logger, interaction, queue);
case 'equalizer':
// TODO: implement
logger.debug('Handling equalizer filters.');
return await this.tempNotImplementedResponse(logger, interaction);
return await this.handleEqualizerFilters(logger, interaction);
case 'disable':
return await this.disableAllFiltersAndRespondWithSuccess(logger, interaction, queue);
}
Expand Down Expand Up @@ -129,6 +133,24 @@ class FiltersCommand extends BaseSlashCommandInteraction {
return await this.sendFiltersEmbed(logger, interaction, 'biquad', filterOptions);
}

private async handleEqualizerFilters(logger: Logger, interaction: ChatInputCommandInteraction): Promise<Message> {
logger.debug('Handling biquad filters.');
const filterOptions: StringSelectMenuOptionBuilder[] = [];

equalizerFilterOptions.availableFilters.forEach((filter: FilterOption) => {
filterOptions.push(
new StringSelectMenuOptionBuilder()
.setLabel(filter.label)
.setDescription(filter.description)
.setValue(filter.value)
.setEmoji(filter.emoji)
.setDefault(false)
);
});

return await this.sendFiltersEmbed(logger, interaction, 'equalizer', filterOptions);
}

private async sendFiltersEmbed(
logger: Logger,
interaction: ChatInputCommandInteraction,
Expand Down Expand Up @@ -218,24 +240,6 @@ class FiltersCommand extends BaseSlashCommandInteraction {
components: []
});
}

private async tempNotImplementedResponse(
logger: Logger,
interaction: ChatInputCommandInteraction
): Promise<Message> {
logger.debug('Responding with info embed.');
return await interaction.editReply({
embeds: [
new EmbedBuilder()
.setDescription(
`**${this.embedOptions.icons.bot} Coming soon**\n` +
'This functionality has not yet been implemented, and will be available soon.'
)
.setColor(this.embedOptions.colors.info)
],
components: []
});
}
}

export default new FiltersCommand();
Loading

0 comments on commit 9584fe8

Please sign in to comment.