Code Monkey home page Code Monkey logo

slack-poker-bot's Introduction

Slack Poker Bot

A bot that turns Slack into a legitimate Texas Hold'em client. Start a game in any channel or private group with 2-10 players. PokerBot will deal hands, direct message players with their hole cards, query players (in order) for their action, determine the winning hand, and handle the pot.

See it in action.

Getting Started

  1. Create a new bot integration
  2. Paste the API token from your integration into main.js OR
  3. Create a token.txt file and paste your API token there
  4. npm install
  5. node src/main.js
  6. To start a game, @<your_bot_name>: Deal
  7. To end a game, @<your_bot_name>: Quit game

Heroku

For the lazy:

Click this button:

Deploy

Manually:
  1. Install Heroku toolbelt
  2. Create new bot integration (as above)
  3. heroku create
  4. heroku config:set SLACK_POKER_BOT_TOKEN=[Slack api integration token]
  5. git push heroku master

But Can It Even?

It can:

  • Initiate a game and poll players to join
  • Handle player order, blinds, and betting
  • Send player's pocket cards as a DM
  • Display board images
  • Handle chip stacks / pot calculations
  • Handle split pots / side pots
  • Determine the best hand

Check the open issues for some planned enhancements.

AI Players

Although this client was built for managing human players in a Slack channel, it has some support for AI players. To add a bot player:

  1. Add a bot class under the ai/ folder
  2. Implement getAction, which is called whenever it is the bot's turn
  3. Modify the addBotPlayers method in src/bot.js to add your bot to every game

Spec All The Things

To run all of the tests, just do:

  1. gulp

The tests produce legible output that matches what users in Slack would see. This is very helpful when diagnosing a logic bug:

Dependencies

  • NodeJS Slack Client node-slack-client abstracts the basics of a Slack bot, including authentication, getting messages from players, and posting messages or attachments to the channel.

  • RxJS The majority of this client is written using RxJS. It simplifies many of the complex player polling interactions, that would otherwise be Death By Timers, into very legible code.

  • Imgur / Lightweight Image Processor Each card is a separate image, and board images are created on the fly by pasting several cards onto a single canvas (with the help of lwip). The resulting image is than uploaded to imgur, which gives us a single URL that can be passed as an attachment to the Slack API. This route was chosen to avoid uploading 311,875,200 images to the cloud, and allows us to modify the card assets easily.

  • Poker Evaluator poker-evaluator is used for evaluating the winning hand when it comes time to show down. Here it has been extended to calculate the best 5-card hand from any 7-card hand.

  • MochaJS Most of the tricky client logic is backed up by tests, which were written using MochaJS.

  • Vector Playing Cards

slack-poker-bot's People

Contributors

charliehess avatar gangstead avatar mcmillan avatar walmsley avatar douglascalhoun avatar

Watchers

James Cloos avatar Peter Levin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.