diff --git a/src/bot.js b/src/bot.js index 3582628..d6d0458 100644 --- a/src/bot.js +++ b/src/bot.js @@ -98,7 +98,6 @@ class Bot { this.isGameRunning = true; let game = new TexasHoldem(this.slack, messages, channel, players); - let gameEnded = game.start(); // Listen for messages directed at the bot containing 'quit game.' messages.where(e => MessageHelpers.containsUserMention(e.text, this.slack.self.id) && @@ -111,7 +110,9 @@ class Bot { game.quit(); }); - return gameEnded.do(() => this.isGameRunning = false); + return rx.Observable.timer(3000) + .flatMap(() => game.start()) + .do(() => this.isGameRunning = false); } // Private: Adds AI-based players (primarily for testing purposes). diff --git a/src/texas-holdem.js b/src/texas-holdem.js index 6a249f3..a9b363e 100644 --- a/src/texas-holdem.js +++ b/src/texas-holdem.js @@ -33,7 +33,19 @@ class TexasHoldem { // them often, and fetching them takes linear time per number of users. this.playerDms = {}; for (let player of this.players) { - this.playerDms[player.id] = this.slack.getDMByName(player.name); + let dm = this.slack.getDMByName(player.name); + this.playerDms[player.id] = dm; + + // If a DM channel hasn't been opened yet, we need to open one first. + if (!dm || !dm.is_open) { + this.slack.openDM(player.id, result => { + if (result.ok) { + this.playerDms[player.id] = this.slack.getDMByName(player.name); + } else { + console.log(`Unable to open DM for ${player.name}: ${result.error}`); + } + }); + } // Each player starts with 100 big blinds. player.chips = this.bigBlind * 100;