From 6baaffb730e1fc3c2057389332cf6f26486cadc2 Mon Sep 17 00:00:00 2001 From: Matt Foxx Date: Tue, 12 Mar 2024 22:25:45 -0400 Subject: Implement volume control #830 (#994) Co-authored-by: Max Isom --- src/commands/config.ts | 27 +++++++++++++++++++++++++++ src/commands/volume.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/commands/volume.ts (limited to 'src/commands') diff --git a/src/commands/config.ts b/src/commands/config.ts index 9441dab..a2bfe93 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -40,6 +40,15 @@ export default class implements Command { .setName('value') .setDescription('whether to announce the next song in the queue automatically') .setRequired(true))) + .addSubcommand(subcommand => subcommand + .setName('set-default-volume') + .setDescription('set default volume used when entering the voice channel') + .addIntegerOption(option => option + .setName('level') + .setDescription('volume percentage (0 is muted, 100 is max & default)') + .setMinValue(0) + .setMaxValue(100) + .setRequired(true))) .addSubcommand(subcommand => subcommand .setName('get') .setDescription('show all settings')); @@ -121,6 +130,23 @@ export default class implements Command { break; } + case 'set-default-volume': { + const value = interaction.options.getInteger('level')!; + + await prisma.setting.update({ + where: { + guildId: interaction.guild!.id, + }, + data: { + defaultVolume: value, + }, + }); + + await interaction.reply('👍 volume setting updated'); + + break; + } + case 'get': { const embed = new EmbedBuilder().setTitle('Config'); @@ -133,6 +159,7 @@ export default class implements Command { : `${config.secondsToWaitAfterQueueEmpties}s`, 'Leave if there are no listeners': config.leaveIfNoListeners ? 'yes' : 'no', 'Auto announce next song in queue': config.autoAnnounceNextSong ? 'yes' : 'no', + 'Default Volume': config.defaultVolume, }; let description = ''; diff --git a/src/commands/volume.ts b/src/commands/volume.ts new file mode 100644 index 0000000..4077c40 --- /dev/null +++ b/src/commands/volume.ts @@ -0,0 +1,42 @@ +import {ChatInputCommandInteraction} from 'discord.js'; +import {TYPES} from '../types.js'; +import {inject, injectable} from 'inversify'; +import PlayerManager from '../managers/player.js'; +import Command from '.'; +import {SlashCommandBuilder} from '@discordjs/builders'; + +@injectable() +export default class implements Command { + public readonly slashCommand = new SlashCommandBuilder() + .setName('volume') + .setDescription('set current player volume level') + .addIntegerOption(option => + option.setName('level') + .setDescription('volume percentage (0 is muted, 100 is max & default)') + .setMinValue(0) + .setMaxValue(100) + .setRequired(true), + ); + + public requiresVC = true; + + private readonly playerManager: PlayerManager; + + constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) { + this.playerManager = playerManager; + } + + public async execute(interaction: ChatInputCommandInteraction): Promise { + const player = this.playerManager.get(interaction.guild!.id); + + const currentSong = player.getCurrent(); + + if (!currentSong) { + throw new Error('nothing is playing'); + } + + const level = interaction.options.getInteger('level') ?? 100; + player.setVolume(level); + await interaction.reply(`Set volume to ${level}%`); + } +} -- cgit v1.2.3