Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Fix: Unmute users when they leave (Fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jftanner committed Oct 10, 2020
1 parent caa4101 commit adc8eac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions classes/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ class Lobby {
// If the player was spectating, remove them.
if (player.isSpectating) this._players.delete(player);

// Update the player's voice state, for having left the channel.
await player.leaveVoiceChannel();

// End the lobby if there are no more connected players.
if (this.players.every(player => !player.guildMember)) {
await this.stop();
Expand Down
9 changes: 7 additions & 2 deletions classes/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class Player {
await this.editGuildMember(false, false, "Left Lobby");
}

async leaveVoiceChannel() {
await this.editGuildMember(false, false, "Left Voice Channel", true);
}

async setForIntermission() {
// Everyone is alive again at intermission.
this.status = STATUS.LIVING;
Expand Down Expand Up @@ -146,8 +150,9 @@ class Player {
* @param {boolean} mute - Whether the player should be allowed to speak
* @param {boolean} deaf - Whether the player should be allowed to hear
* @param {string} [reason] - Reason for changing the settings.
* @param {boolean} [anyChannel] - Update the voice state regardless of the channel the user is in.
*/
async editGuildMember(mute, deaf, reason) {
async editGuildMember(mute, deaf, reason, anyChannel = false) {
// If there's no connected guild member, ignore this.
if (!this._guildMember) return;

Expand All @@ -156,7 +161,7 @@ class Player {
const { voice } = member;

// Don't adjust voice settings for other channels.
const updateVoice = voice && voice.channelID === this.voiceChannelId
const updateVoice = anyChannel || (voice && voice.channelID === this.voiceChannelId);

// Decide which nickname to use.
const nick = this.isSpectating ? this._originalNickname : this.amongUsName;
Expand Down

0 comments on commit adc8eac

Please sign in to comment.