From 3cf0656190e24a38a57d4288eeb60687d215d904 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 14 May 2024 16:23:31 -0400 Subject: [PATCH] Lock/Unlock for Voice Dispatchers --- commands/games-sp/hearing-test.js | 2 ++ package.json | 2 +- structures/VoiceDispatcher.js | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/commands/games-sp/hearing-test.js b/commands/games-sp/hearing-test.js index 38d6b74c..db943b7b 100644 --- a/commands/games-sp/hearing-test.js +++ b/commands/games-sp/hearing-test.js @@ -41,6 +41,7 @@ module.exports = class HearingTestCommand extends Command { let range; let previousAge = 'all'; let previousRange = 8; + connection.lock(); const gameMsg = await msg.say('Here\'s the first sound. Listen carefully!'); let buttonPress; for (const { age: dataAge, khz, file } of data) { @@ -79,6 +80,7 @@ module.exports = class HearingTestCommand extends Command { components: [] }); } + connection.unlock(); if (age === 'all') { return gameMsg.edit({ content: 'Everyone should be able to hear that. You cannot hear.', diff --git a/package.json b/package.json index f22532c5..a7d61f2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "151.2.0", + "version": "151.2.1", "description": "Your personal server companion.", "main": "Xiao.js", "private": true, diff --git a/structures/VoiceDispatcher.js b/structures/VoiceDispatcher.js index ea319d3d..68d4bfef 100644 --- a/structures/VoiceDispatcher.js +++ b/structures/VoiceDispatcher.js @@ -5,6 +5,7 @@ module.exports = class VoiceDispatcher { this.channel = channel; this.player = createAudioPlayer(); getVoiceConnection(channel.guild.id).subscribe(this.player); + this.locked = false; } play(content) { @@ -33,6 +34,16 @@ module.exports = class VoiceDispatcher { return this.player.unpause(); } + lock() { + this.locked = true; + return this.locked; + } + + unlock() { + this.locked = false; + return this.locked; + } + get connection() { return getVoiceConnection(this.guild.id); } @@ -46,6 +57,6 @@ module.exports = class VoiceDispatcher { } get canPlay() { - return this.player.state.status === AudioPlayerStatus.Idle; + return this.player.state.status === AudioPlayerStatus.Idle && !this.locked; } };