mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 06:28:53 +00:00
fix: refactored filters select menu component
This commit is contained in:
1 parent
9458ed60a1
commit
a9ce285650
1 file changed
+40
-39
@@ -6,6 +6,7 @@ import { FFmpegFilterOption, FFmpegFilterOptions } 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');
|
||||||
|
|
||||||
@@ -29,25 +30,25 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
|||||||
checkQueueExists
|
checkQueueExists
|
||||||
]);
|
]);
|
||||||
|
|
||||||
queue.filters.ffmpeg.setInputArgs([
|
this.resetFilters(queue, logger);
|
||||||
'-threads',
|
this.enableNormalizerIfRequired(selectMenuInteraction);
|
||||||
ffmpegFilterOptions.threadAmount,
|
this.enableProvidedFilters(selectMenuInteraction, queue, logger);
|
||||||
'-reconnect',
|
|
||||||
'1',
|
|
||||||
'-reconnect_streamed',
|
|
||||||
'1',
|
|
||||||
'-reconnect_delay_max',
|
|
||||||
'10',
|
|
||||||
'-vn'
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Reset filters before enabling provided filters
|
logger.debug('Responding with success embed.');
|
||||||
|
return await selectMenuInteraction.editReply({
|
||||||
|
embeds: [this.buildSuccessEmbed(selectMenuInteraction)],
|
||||||
|
components: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private resetFilters(queue: GuildQueue, logger: Logger) {
|
||||||
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.');
|
logger.debug('Reset queue filters.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if bassboost is enabled and not normalizer, also enable normalizer to avoid distrorion
|
private enableNormalizerIfRequired(selectMenuInteraction: StringSelectMenuInteraction) {
|
||||||
if (
|
if (
|
||||||
ffmpegFilterOptions.forceNormalizerByBassBoost &&
|
ffmpegFilterOptions.forceNormalizerByBassBoost &&
|
||||||
(selectMenuInteraction.values.includes('bassboost_low') ||
|
(selectMenuInteraction.values.includes('bassboost_low') ||
|
||||||
@@ -56,38 +57,38 @@ class FiltersSelectMenuComponent extends BaseComponentInteraction {
|
|||||||
) {
|
) {
|
||||||
selectMenuInteraction.values.push('normalizer');
|
selectMenuInteraction.values.push('normalizer');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Enable provided filters
|
private enableProvidedFilters(
|
||||||
|
selectMenuInteraction: StringSelectMenuInteraction,
|
||||||
|
queue: GuildQueue,
|
||||||
|
logger: Logger
|
||||||
|
) {
|
||||||
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
|
queue.filters.ffmpeg.toggle(selectMenuInteraction.values as (keyof QueueFilters)[]);
|
||||||
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
logger.debug(`Enabled filters ${selectMenuInteraction.values.join(', ')}.`);
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug('Responding with success embed.');
|
private buildSuccessEmbed(selectMenuInteraction: StringSelectMenuInteraction) {
|
||||||
return await selectMenuInteraction.editReply({
|
return new EmbedBuilder()
|
||||||
embeds: [
|
.setAuthor(this.getEmbedUserAuthor(selectMenuInteraction))
|
||||||
new EmbedBuilder()
|
.setDescription(
|
||||||
.setAuthor(this.getEmbedUserAuthor(interaction))
|
`**${
|
||||||
.setDescription(
|
this.embedOptions.icons.success
|
||||||
`**${
|
} Filters toggled**\nNow using these filters:\n${selectMenuInteraction.values
|
||||||
this.embedOptions.icons.success
|
.map((enabledFilter: string) => {
|
||||||
} Filters toggled**\nNow using these filters:\n${selectMenuInteraction.values
|
const filter: FFmpegFilterOption | undefined = ffmpegFilterOptions.availableFilters.find(
|
||||||
.map((enabledFilter: string) => {
|
(filter) => enabledFilter == filter.value
|
||||||
const filter: FFmpegFilterOption | undefined =
|
);
|
||||||
ffmpegFilterOptions.availableFilters.find(
|
|
||||||
(filter) => enabledFilter == filter.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!filter) {
|
if (!filter) {
|
||||||
return enabledFilter;
|
return enabledFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `- **${filter.emoji} ${filter.label}**`;
|
return `- **${filter.emoji} ${filter.label}**`;
|
||||||
})
|
})
|
||||||
.join('\n')}`
|
.join('\n')}`
|
||||||
)
|
)
|
||||||
.setColor(this.embedOptions.colors.success)
|
.setColor(this.embedOptions.colors.success);
|
||||||
],
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user