Skip to content

Commit

Permalink
Handle unopened DM channels. (Brute-force way now: we're just waiting…
Browse files Browse the repository at this point in the history
… a while before we start).

In the long run we should have this process block the game from progressing.
  • Loading branch information
CharlieHess committed Aug 28, 2015
1 parent 177c5c8 commit fcdbf5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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).
Expand Down
14 changes: 13 additions & 1 deletion src/texas-holdem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fcdbf5c

Please sign in to comment.