mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 22:16:13 +00:00
feat: added equalizer filters to /filters command
This commit is contained in:
1 parent
ebe20fe8c8
commit
9584fe8ebe
4 files changed
+213
-38
No files matched your search
+129
-10
@@ -205,6 +205,12 @@ 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: '📈'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -212,61 +218,61 @@ module.exports.ffmpegFilterOptions = {
|
||||
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: '🔊'
|
||||
@@ -274,6 +280,119 @@ module.exports.biquadFilterOptions = {
|
||||
]
|
||||
};
|
||||
|
||||
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 = {
|
||||
|
||||
@@ -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() {
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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,
|
||||
@@ -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();
|
||||
@@ -1,15 +1,21 @@
|
||||
import config from 'config';
|
||||
import { BiquadFilters, GuildQueue, QueueFilters, useQueue } from 'discord-player';
|
||||
import { BiquadFilters, EqualizerConfigurationPreset, GuildQueue, QueueFilters, useQueue } from 'discord-player';
|
||||
import { EmbedBuilder, Message, StringSelectMenuInteraction } from 'discord.js';
|
||||
import { Logger } from 'pino';
|
||||
import { BaseComponentInteraction } from '../../classes/interactions';
|
||||
import { BiquadFilterOptions, FFmpegFilterOptions, FilterOption } from '../../types/configTypes';
|
||||
import {
|
||||
EqualizerFilterOptions,
|
||||
BiquadFilterOptions,
|
||||
FFmpegFilterOptions,
|
||||
FilterOption
|
||||
} from '../../types/configTypes';
|
||||
import { BaseComponentParams, BaseComponentReturnType } from '../../types/interactionTypes';
|
||||
import { 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 FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
constructor() {
|
||||
@@ -44,9 +50,7 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
case 'biquad':
|
||||
return await this.handleBiquadFilterToggle(logger, selectMenuInteraction, queue, filterType);
|
||||
case 'equalizer':
|
||||
// TODO: implement
|
||||
logger.info('equalizer');
|
||||
break;
|
||||
return await this.handleEqualizerFilterToggle(logger, selectMenuInteraction, queue, filterType);
|
||||
default:
|
||||
logger.warn(`Unknown filter type '${filterType}'.`);
|
||||
return;
|
||||
@@ -78,12 +82,28 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
return await this.sendFiltersToggledSuccessEmbed(logger, selectMenuInteraction, filterType);
|
||||
}
|
||||
|
||||
private async handleEqualizerFilterToggle(
|
||||
logger: Logger,
|
||||
selectMenuInteraction: StringSelectMenuInteraction,
|
||||
queue: GuildQueue,
|
||||
filterType: string
|
||||
): Promise<Message> {
|
||||
this.toggleEqualizerFilter(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 {
|
||||
if (!queue.filters.ffmpeg) {
|
||||
throw new Error('FFmpeg filter is not enabled.');
|
||||
}
|
||||
|
||||
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
|
||||
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
||||
} catch (error) {
|
||||
@@ -98,6 +118,11 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
): void {
|
||||
try {
|
||||
queue.filters.biquad!.enable();
|
||||
|
||||
if (!queue.filters.biquad) {
|
||||
throw new Error('Biquad filter is not enabled.');
|
||||
}
|
||||
|
||||
queue.filters.biquad!.setGain(5);
|
||||
queue.filters.biquad!.setFilter(selectMenuInteraction.values[0] as BiquadFilters);
|
||||
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
||||
@@ -106,6 +131,28 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
}
|
||||
}
|
||||
|
||||
private toggleEqualizerFilter(
|
||||
selectMenuInteraction: StringSelectMenuInteraction,
|
||||
queue: GuildQueue,
|
||||
logger: Logger
|
||||
): void {
|
||||
try {
|
||||
queue.filters.equalizer!.enable();
|
||||
|
||||
const inputFilter = selectMenuInteraction.values[0] as keyof typeof EqualizerConfigurationPreset;
|
||||
const eqFilter = EqualizerConfigurationPreset[inputFilter];
|
||||
|
||||
if (!queue.filters.equalizer) {
|
||||
throw new Error('Equalizer filter is not enabled.');
|
||||
}
|
||||
|
||||
queue.filters.equalizer!.setEQ(eqFilter);
|
||||
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);
|
||||
@@ -159,7 +206,8 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
||||
availableFilters = biquadFilterOptions.availableFilters;
|
||||
break;
|
||||
case 'equalizer':
|
||||
break; // TODO: implement
|
||||
availableFilters = equalizerFilterOptions.availableFilters;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Vendored
+4
@@ -124,6 +124,10 @@ export type BiquadFilterOptions = {
|
||||
availableFilters: FFmpegFilterOption[];
|
||||
};
|
||||
|
||||
export type EqualizerFilterOptions = {
|
||||
availableFilters: FFmpegFilterOption[];
|
||||
};
|
||||
|
||||
export type LoadTestOptions = {
|
||||
enabled: boolean;
|
||||
trackUrl: string;
|
||||
|
||||
Reference in new issue
Block a user