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

Commit

Permalink
New: Spectator behavior is configurable.
Browse files Browse the repository at this point in the history
Use `!sau config set spectators <option>`:
- `mute`: (Default) Keep spectators muted during the game.
- `ignore`: Never mute/unmute spectators.
- `dynamic`: Treat spectators like dead people. (**Not** recommended.)

Fixes #43
  • Loading branch information
jftanner committed Nov 2, 2020
1 parent 0c68169 commit 8a1080e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
15 changes: 15 additions & 0 deletions classes/GuildConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ const SETTINGS = {
throw new Error("Autojoin must be either `on` or `off`");
}
},
spectators: {
defaultValue: 'mute',
description: [
'Controls how spectators are handled during the game:',
'- `mute`: Mute spectators during the working and meeting phases.',
'- `ignore`: Ignore spectators entirely, never muting/unmuting them.',
'- `dynamic`: Treat spectators like dead players. (**Will** cause severe lag with 10+ users.)'
].join('\n'),
options: ['mute', 'ignore', 'dynamic'],
setter: (value) => {
const parsed = value?.toLowerCase().trim();
if (!SETTINGS.spectators.options.includes(parsed)) throw new Error("That's not a valid option.");
return parsed;
}
},
speech: {
defaultValue: true,
description: "When enabled, the bot will play spoken announcements into the voice channel.",
Expand Down
31 changes: 22 additions & 9 deletions classes/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Player {
constructor(lobby, guildMember, { ...document } = { status: STATUS.SPECTATING }) {
this._document = document;

// Attach the voice channel.
this._voiceChannelId = lobby.voiceChannel.id;
// Attach the lobby..
this._lobby = lobby;

// Attach the guild member, if provided.
if (guildMember) this.linkGuildMember(guildMember);
Expand Down Expand Up @@ -154,8 +154,8 @@ class Player {
async leaveGame() {
delete this._document.amongUsName;
delete this._document.amongUsColor;
this.status = STATUS.SPECTATING;
await this.editGuildMember(false, false, "Left Lobby");
this.status = STATUS.SPECTATING;
}

async setForIntermission() {
Expand All @@ -167,9 +167,13 @@ class Player {
}

async setForWorking() {
// Spectators are muted.
// Spectators are handled according to the guild configuration.
if (this.isSpectating) {
await this.editGuildMember(true, false, "Spectator");
// Spectators are only unmuted in the Working phase if the `dynamic` setting is used.
if (await this._lobby.getGuildConfig('spectators') === 'dynamic')
await this.editGuildMember(false, false, "Spectator (Dynamic)");
else
await this.editGuildMember(true, false, "Spectator");
return;
}

Expand All @@ -180,7 +184,7 @@ class Player {
}

async setForMeeting() {
// Spectators are muted.
// Spectators are muted or ignored.
if (this.isSpectating) {
await this.editGuildMember(true, false, "Spectator");
return;
Expand Down Expand Up @@ -215,10 +219,19 @@ class Player {
const { voice } = member;

// Don't adjust voice settings for other channels.
const updateVoice = voice?.channelID && (anyChannel || voice.channelID === this._voiceChannelId);
let updateVoice = voice?.channelID && (anyChannel || voice.channelID === this._lobby.voiceChannel.id);

// By default, use the user's in-game name as their Discord nickname.
let nick = this.amongUsName;

// Decide which nickname to use.
const nick = this.isSpectating ? this.originalNickname : this.amongUsName;
// Handle spectators differently.
if (this.isSpectating) {
// Don't update spectators' voice state if set to `ignore`.
if (await this._lobby.getGuildConfig('spectators') === 'ignore') updateVoice = false;

// Reset their nickname to the original.
nick = this.originalNickname;
}

// Build the patch object.
const patch = {};
Expand Down

0 comments on commit 8a1080e

Please sign in to comment.