-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement an optional "master volume control" command #830
* Enabled using env VOLUME_CONTROL=true * Disabled by default
- Loading branch information
Showing
8 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ SPOTIFY_CLIENT_SECRET= | |
# BOT_ACTIVITY_TYPE= | ||
# BOT_ACTIVITY_URL= | ||
# BOT_ACTIVITY= | ||
|
||
# VOLUME_CONTROL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {ChatInputCommandInteraction, PermissionFlagsBits} 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 player volume level') | ||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild.toString()) | ||
.addIntegerOption(option => | ||
option.setName('level') | ||
.setDescription('percentage as number EG 0 is muted, 100 is default max volume') | ||
.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<void> { | ||
const player = this.playerManager.get(interaction.guild!.id); | ||
|
||
if (!player.canControlVolume()) { | ||
throw new Error('Ope, sorry but I\'m not configured to allow volume control! You can enable it by starting the bot with env VOLUME_CONTROL=true'); | ||
} | ||
|
||
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}%`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters