From 46a81fb474b223c16584c88b9339c125c74003d1 Mon Sep 17 00:00:00 2001 From: Aaron Sandoval <89826250+aarons124@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:26:35 -0700 Subject: [PATCH 1/3] chore: update volume command options - Adjusted the volume command options in the Discord bot to have a minimum value of 1. - Updated the corresponding validation in the execute method. - Cleaned up unnecessary conditions in the execute method. - Updated the TypeScript file to reflect these changes. --- src/interactions/commands/player/volume.ts | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/interactions/commands/player/volume.ts diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts new file mode 100644 index 0000000..6ad73cd --- /dev/null +++ b/src/interactions/commands/player/volume.ts @@ -0,0 +1,113 @@ +import { GuildQueue, useQueue } from 'discord-player'; +import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js'; +import { BaseSlashCommandInteraction } from '../../../classes/interactions'; +import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; +import { checkQueueExists } from '../../../utils/validation/queueValidator'; +import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; +import { Logger } from 'pino'; +import { localizeCommand, useServerTranslator } from '../../../common/localeUtil'; +import { TFunction } from 'i18next'; + +class VolumeCommand extends BaseSlashCommandInteraction { + constructor() { + const data = localizeCommand( + new SlashCommandBuilder() + .setName('volume') + .addIntegerOption((option) => option.setName('percentage').setMinValue(1).setMaxValue(100)) + ); + super(data); + } + + async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { + const { executionId, interaction } = params; + const logger = this.getLogger(this.name, executionId, interaction); + const translator = useServerTranslator(interaction); + + const queue: GuildQueue = useQueue(interaction.guild!.id)!; + + await this.runValidators({ interaction, queue, executionId }, [ + checkInVoiceChannel, + checkSameVoiceChannel, + checkQueueExists + ]); + + const volume: number = interaction.options.getInteger('percentage')!; + + if (!volume && volume !== 0) { + return await this.handleShowCurrentVolume(queue, logger, interaction, translator); + } else { + return await this.handleValidVolumeInput(volume, queue, logger, interaction, translator); + } + } + + private async handleShowCurrentVolume( + queue: GuildQueue, + logger: Logger, + interaction: ChatInputCommandInteraction, + translator: TFunction + ) { + const currentVolume: number = queue.node.volume; + logger.debug('No volume input was provided, showing current volume.'); + + const currentVolumeIcon = + currentVolume === 0 ? this.embedOptions.icons.volumeIsMuted : this.embedOptions.icons.volume; + + logger.debug('Responding with info embed.'); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setDescription( + translator('commands.volume.volumeInformation', { + icon: currentVolumeIcon, + volume: currentVolume + }) + ) + .setColor(this.embedOptions.colors.info) + ] + }); + } + + private async handleValidVolumeInput( + volume: number, + queue: GuildQueue, + logger: Logger, + interaction: ChatInputCommandInteraction, + translator: TFunction + ) { + queue.node.setVolume(volume); + logger.debug(`Set volume to ${volume}%.`); + + if (volume === 0) { + logger.debug('Responding with success embed.'); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor(this.getEmbedUserAuthor(interaction)) + .setDescription( + translator('commands.volume.volumeMuted', { + icon: this.embedOptions.icons.volumeMuted + }) + ) + .setColor(this.embedOptions.colors.success) + ] + }); + } + + logger.debug('Responding with success embed.'); + return await interaction.editReply({ + embeds: [ + new EmbedBuilder() + .setAuthor(this.getEmbedUserAuthor(interaction)) + .setDescription( + translator('commands.volume.volumeChanged', { + icon: this.embedOptions.icons.volumeChanged, + volume + }) + ) + .setColor(this.embedOptions.colors.success) + ] + }); + } +} + +export default new VolumeCommand(); From d48503f565f4b0104e9f48891ece6c808e1f81f9 Mon Sep 17 00:00:00 2001 From: Aaron Sandoval <89826250+aarons124@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:36:44 -0700 Subject: [PATCH 2/3] chore: update volume command options and remove duplicate file - Adjusted the volume command optionsto have a minimum value of 1 and a maximum value of 100. - Updated the corresponding validation in the execute method. - Cleaned up unnecessary conditions in the execute method. - Deleted a duplicate volume.ts file. - Updated the TypeScript file to reflect these changes. --- src/interactions/commands/player/volume.ts | 113 --------------------- src/interactions/slashcommands/volume.ts | 27 +---- 2 files changed, 1 insertion(+), 139 deletions(-) delete mode 100644 src/interactions/commands/player/volume.ts diff --git a/src/interactions/commands/player/volume.ts b/src/interactions/commands/player/volume.ts deleted file mode 100644 index 6ad73cd..0000000 --- a/src/interactions/commands/player/volume.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { GuildQueue, useQueue } from 'discord-player'; -import { ChatInputCommandInteraction, EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import { BaseSlashCommandInteraction } from '../../../classes/interactions'; -import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes'; -import { checkQueueExists } from '../../../utils/validation/queueValidator'; -import { checkInVoiceChannel, checkSameVoiceChannel } from '../../../utils/validation/voiceChannelValidator'; -import { Logger } from 'pino'; -import { localizeCommand, useServerTranslator } from '../../../common/localeUtil'; -import { TFunction } from 'i18next'; - -class VolumeCommand extends BaseSlashCommandInteraction { - constructor() { - const data = localizeCommand( - new SlashCommandBuilder() - .setName('volume') - .addIntegerOption((option) => option.setName('percentage').setMinValue(1).setMaxValue(100)) - ); - super(data); - } - - async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType { - const { executionId, interaction } = params; - const logger = this.getLogger(this.name, executionId, interaction); - const translator = useServerTranslator(interaction); - - const queue: GuildQueue = useQueue(interaction.guild!.id)!; - - await this.runValidators({ interaction, queue, executionId }, [ - checkInVoiceChannel, - checkSameVoiceChannel, - checkQueueExists - ]); - - const volume: number = interaction.options.getInteger('percentage')!; - - if (!volume && volume !== 0) { - return await this.handleShowCurrentVolume(queue, logger, interaction, translator); - } else { - return await this.handleValidVolumeInput(volume, queue, logger, interaction, translator); - } - } - - private async handleShowCurrentVolume( - queue: GuildQueue, - logger: Logger, - interaction: ChatInputCommandInteraction, - translator: TFunction - ) { - const currentVolume: number = queue.node.volume; - logger.debug('No volume input was provided, showing current volume.'); - - const currentVolumeIcon = - currentVolume === 0 ? this.embedOptions.icons.volumeIsMuted : this.embedOptions.icons.volume; - - logger.debug('Responding with info embed.'); - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('commands.volume.volumeInformation', { - icon: currentVolumeIcon, - volume: currentVolume - }) - ) - .setColor(this.embedOptions.colors.info) - ] - }); - } - - private async handleValidVolumeInput( - volume: number, - queue: GuildQueue, - logger: Logger, - interaction: ChatInputCommandInteraction, - translator: TFunction - ) { - queue.node.setVolume(volume); - logger.debug(`Set volume to ${volume}%.`); - - if (volume === 0) { - logger.debug('Responding with success embed.'); - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setAuthor(this.getEmbedUserAuthor(interaction)) - .setDescription( - translator('commands.volume.volumeMuted', { - icon: this.embedOptions.icons.volumeMuted - }) - ) - .setColor(this.embedOptions.colors.success) - ] - }); - } - - logger.debug('Responding with success embed.'); - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setAuthor(this.getEmbedUserAuthor(interaction)) - .setDescription( - translator('commands.volume.volumeChanged', { - icon: this.embedOptions.icons.volumeChanged, - volume - }) - ) - .setColor(this.embedOptions.colors.success) - ] - }); - } -} - -export default new VolumeCommand(); diff --git a/src/interactions/slashcommands/volume.ts b/src/interactions/slashcommands/volume.ts index 3c8307d..ebb110d 100644 --- a/src/interactions/slashcommands/volume.ts +++ b/src/interactions/slashcommands/volume.ts @@ -13,7 +13,7 @@ class VolumeCommand extends BaseSlashCommandInteraction { const data = localizeCommand( new SlashCommandBuilder() .setName('volume') - .addIntegerOption((option) => option.setName('percentage').setMinValue(0).setMaxValue(100)) + .addIntegerOption((option) => option.setName('percentage').setMinValue(1).setMaxValue(100)) ); super(data); } @@ -35,8 +35,6 @@ class VolumeCommand extends BaseSlashCommandInteraction { if (!volume && volume !== 0) { return await this.handleShowCurrentVolume(queue, logger, interaction, translator); - } else if (volume > 100 || volume < 0) { - return await this.handleInvalidVolumeInput(volume, logger, interaction, translator); } else { return await this.handleValidVolumeInput(volume, queue, logger, interaction, translator); } @@ -69,29 +67,6 @@ class VolumeCommand extends BaseSlashCommandInteraction { }); } - private async handleInvalidVolumeInput( - volume: number, - logger: Logger, - interaction: ChatInputCommandInteraction, - translator: TFunction - ) { - logger.debug('Volume specified was higher than 100% or lower than 0%.'); - - logger.debug('Responding with warning embed.'); - return await interaction.editReply({ - embeds: [ - new EmbedBuilder() - .setDescription( - translator('commands.volume.invalidVolumeRange', { - icon: this.embedOptions.icons.warning, - wrongVolume: volume - }) - ) - .setColor(this.embedOptions.colors.warning) - ] - }); - } - private async handleValidVolumeInput( volume: number, queue: GuildQueue, From 23fd73997a58fb2d0437367e856bf86098e8ad3f Mon Sep 17 00:00:00 2001 From: Aaron Sandoval <89826250+aarons124@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:54:12 -0700 Subject: [PATCH 3/3] Update volume command option to minimum value of 0 for percentage --- src/interactions/slashcommands/volume.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interactions/slashcommands/volume.ts b/src/interactions/slashcommands/volume.ts index ebb110d..e4fa222 100644 --- a/src/interactions/slashcommands/volume.ts +++ b/src/interactions/slashcommands/volume.ts @@ -13,7 +13,7 @@ class VolumeCommand extends BaseSlashCommandInteraction { const data = localizeCommand( new SlashCommandBuilder() .setName('volume') - .addIntegerOption((option) => option.setName('percentage').setMinValue(1).setMaxValue(100)) + .addIntegerOption((option) => option.setName('percentage').setMinValue(0).setMaxValue(100)) ); super(data); }