diff --git a/src/ConversationHelper.ts b/src/ConversationHelper.ts index b8ccaae..6945483 100644 --- a/src/ConversationHelper.ts +++ b/src/ConversationHelper.ts @@ -316,7 +316,7 @@ export async function getPlayerList( } catch (errorCollected) { collected = errorCollected; } - Log.info(collected); + Log.log('Collected a reaction'); if (collected.array().length === 0) { return []; } diff --git a/src/Game.ts b/src/Game.ts index 6e8402d..7654378 100644 --- a/src/Game.ts +++ b/src/Game.ts @@ -1,4 +1,4 @@ -import { TextChannel, VoiceChannel, GuildMember, User } from 'discord.js'; +import { TextChannel, VoiceChannel, GuildMember } from 'discord.js'; import { MAXIMUM_PLAYERS, MINIMUM_PLAYERS, @@ -38,7 +38,6 @@ export class Game { private _startTime: Date | null; public newDoppelgangerRole: RoleName | null; private _hasVoice: boolean; - private _initiator: User; private _soundManager: SoundManager; private _phase: Phase; @@ -47,7 +46,8 @@ export class Game { textChannel: TextChannel, voiceChannel: VoiceChannel, chosenRoles: RoleName[], - initiator: User + silentNight: boolean, + silent: boolean ) { if (players.length < MINIMUM_PLAYERS || players.length > MAXIMUM_PLAYERS) { throw new Error('Invalid amount of players'); @@ -60,8 +60,11 @@ export class Game { this._started = false; this._startTime = null; this.newDoppelgangerRole = null; - this._initiator = initiator; - this._soundManager = new SoundManager(voiceChannel.guild.id); + this._soundManager = new SoundManager( + voiceChannel.guild.id, + silentNight, + silent + ); this._phase = Phase.night; try { @@ -70,14 +73,10 @@ export class Game { Log.info('Joining voice channel.'); } catch (error) { this._hasVoice = false; - Log.info('Not joining voice, already in a voice channel.'); + Log.info(error.message); } } - public get initiator(): User { - return this._initiator; - } - public get startGameState(): GameState { return this._startGameState; } diff --git a/src/GamesManager.ts b/src/GamesManager.ts index 75d68b1..2af6a05 100644 --- a/src/GamesManager.ts +++ b/src/GamesManager.ts @@ -1,10 +1,4 @@ -import { - Collection, - TextChannel, - VoiceChannel, - GuildMember, - User, -} from 'discord.js'; +import { Collection, TextChannel, VoiceChannel, GuildMember } from 'discord.js'; import { CARDS_ON_TABLE } from './Constants'; import { RoleName } from './enums/RoleName'; import { Game } from './Game'; @@ -20,10 +14,11 @@ class GamesManager { } public quickStartGame( - initiator: User, players: GuildMember[], textChannel: TextChannel, - voiceChannel: VoiceChannel + voiceChannel: VoiceChannel, + silentNight: boolean, + silent: boolean ): void { const quickStartRoles = this._quickStart.get(textChannel.id); if (quickStartRoles === undefined) { @@ -36,19 +31,21 @@ class GamesManager { ); } this.startNewGame( - initiator, players, textChannel, voiceChannel, + silentNight, + silent, quickStartRoles ); } public startNewGame( - initiator: User, players: GuildMember[], textChannel: TextChannel, voiceChannel: VoiceChannel, + silentNight: boolean, + silent: boolean, roleNames: RoleName[] ): void { if (this._games.has(textChannel.id)) { @@ -62,7 +59,8 @@ class GamesManager { textChannel, voiceChannel, roleNames, - initiator + silentNight, + silent ); this._games.set(textChannel.id, game); diff --git a/src/SoundManager.ts b/src/SoundManager.ts index 1e9029d..6d40983 100644 --- a/src/SoundManager.ts +++ b/src/SoundManager.ts @@ -9,12 +9,16 @@ export class SoundManager { private _connection: VoiceConnection | null; private _dispatcher: StreamDispatcher | null; private _guildId: string; + private _silentNight: boolean; + private _silent: boolean; - constructor(guildId: string) { + constructor(guildId: string, silentNight: boolean, silent: boolean) { this._voiceChannel = null; this._connection = null; this._dispatcher = null; this._guildId = guildId; + this._silentNight = silentNight; + this._silent = silent; this.disconnectWhenEmpty(); } @@ -23,10 +27,17 @@ export class SoundManager { if (client.isUsingVoice(this._guildId, voiceChannel)) { throw new Error('Already connected to a voice channel of this guild.'); } + if (this._silent) { + throw new Error('Running in silent mode.'); + } this._voiceChannel = voiceChannel; } public async startNightLoop(): Promise { + if (this._silentNight || this._silent) { + Log.info('Silent night mode, not playing night loop'); + return; + } Log.info('Starting night loop'); if (!this._voiceChannel) { @@ -42,11 +53,19 @@ export class SoundManager { if (!this._voiceChannel) { return; } - await this.fadeOut(1); - this._dispatcher = this.play(Sound.rooster); + if (!this._silentNight && !this._silent) { + await this.fadeOut(1); + } + if (!this._silent) { + this._dispatcher = this.play(Sound.rooster); + } } public playGong(): void { + if (this._silent) { + Log.info('Silent night mode, not playing "time almost up" sample'); + return; + } Log.info('Playing "time almost up" sample'); this.play(Sound.gong); } @@ -71,7 +90,7 @@ export class SoundManager { } this._dispatcher.setVolume(volume); await new Promise((resolve) => setTimeout(resolve, 100)); - await this.fadeOut(volume - 0.025); + await this.fadeOut(volume - 0.05); } public stop(): void { diff --git a/src/commands/Start.ts b/src/commands/Start.ts index 26ca2bc..2d49d4c 100644 --- a/src/commands/Start.ts +++ b/src/commands/Start.ts @@ -11,14 +11,29 @@ import { getGamesManagerInstance } from '../GamesManager'; import { Log } from '../Log'; import { Command } from '../types/Command'; +enum Optional { + quick = 'quick', + silentnight = 'silentnight', + silent = 'silent', +} + const command: Command = { names: ['start'], - description: - "Start a new game. Supply the _'quick'_ option to reuse previous settings.", + description: `Start a new game. Supply the _'quick'_ option to reuse previous settings. +Supply the _'silentnight'_ option to mute the ambient night noises. +Supply the _'silent'_ option to mute all sound effects.`, params: [ { optional: true, - name: 'quick', + name: Optional.quick, + }, + { + optional: true, + name: Optional.silentnight, + }, + { + optional: true, + name: Optional.silent, }, ], execute, @@ -29,10 +44,10 @@ async function execute(msg: Message, args: string[]): Promise { const textChannel = msg.channel as TextChannel; const gamesManager = getGamesManagerInstance(); - let quickStart = false; - if (args[0] === 'quick') { - quickStart = true; - } + const lowerArgs = args.map((arg) => arg.toLowerCase()); + const quickStart = lowerArgs.includes(Optional.quick); + const silentNight = lowerArgs.includes(Optional.silentnight); + const silent = lowerArgs.includes(Optional.silent); const voiceChannel = msg.member?.voice.channel; if (!voiceChannel) { @@ -81,10 +96,11 @@ async function execute(msg: Message, args: string[]): Promise { } if (quickStart) { await gamesManager.quickStartGame( - msg.author, players, msg.channel as TextChannel, - voiceChannel + voiceChannel, + silentNight, + silent ); } else { const roles = [ @@ -92,10 +108,11 @@ async function execute(msg: Message, args: string[]): Promise { ...(await ChooseRoles(author, textChannel, amountToPick)), ]; await gamesManager.startNewGame( - msg.author, players, msg.channel as TextChannel, voiceChannel, + silentNight, + silent, roles ); } diff --git a/test/Game.unit.test.ts b/test/Game.unit.test.ts index da558cb..d2ae159 100644 --- a/test/Game.unit.test.ts +++ b/test/Game.unit.test.ts @@ -52,7 +52,8 @@ function newGame(size: number, players: Player[] = []): Game { textChannel, voiceChannel, roles, - users[0].user + false, + false ); }