From 6e403de83adb66266e6f1788f49fa619e93ded33 Mon Sep 17 00:00:00 2001 From: Charlie Hess Date: Thu, 23 Jul 2015 15:43:38 -0700 Subject: [PATCH] Store the token in a separate file which is never checked in. --- .gitignore | 1 + README.md | 3 ++- src/bot.js | 6 +----- src/main.js | 10 +++++++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index e0e6e61..ea2f36d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ output/ +token.txt diff --git a/README.md b/README.md index 95261c6..c17d6b4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ A bot that turns Slack into a legitimate Texas Hold'em client. Start a game in a ### Getting Started 1. Create a new [bot integration](https://my.slack.com/services/new/bot) -1. Add your API token to `main.js` +1. Paste the API token from your integration into `main.js` _OR_ +1. Create a `token.txt` file and paste your API token there 1. `npm install` 1. `node src/main.js` 1. To start a game, `@: Deal` diff --git a/src/bot.js b/src/bot.js index 3afd06f..6dfa46c 100644 --- a/src/bot.js +++ b/src/bot.js @@ -14,11 +14,7 @@ class Bot { // // token - An API token from the bot integration constructor(token) { - if (token === 'YOUR-TOKEN-GOES-HERE') { - throw new Error('Use a valid API token!'); - } else { - this.slack = new Slack(token, true, true); - } + this.slack = new Slack(token, true, true); } // Public: Brings this bot online and starts handling messages sent to it. diff --git a/src/main.js b/src/main.js index 13b7ed9..fb1613b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,13 @@ require('babel/register'); +try { + var fs = require('fs'); + var token = fs.readFileSync('token.txt', 'utf8').trim(); +} catch (error) { + console.log("Your API token should be placed in a 'token.txt' file, which is missing."); + return; +} + var Bot = require('./bot'); -var bot = new Bot('YOUR-TOKEN-GOES-HERE'); +var bot = new Bot(token); bot.login();