Skip to content

Commit 6e403de

Browse files
committed
Store the token in a separate file which is never checked in.
1 parent c89c0cc commit 6e403de

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
output/
3+
token.txt

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ A bot that turns Slack into a legitimate Texas Hold'em client. Start a game in a
55

66
### Getting Started
77
1. Create a new [bot integration](https://my.slack.com/services/new/bot)
8-
1. Add your API token to `main.js`
8+
1. Paste the API token from your integration into `main.js` _OR_
9+
1. Create a `token.txt` file and paste your API token there
910
1. `npm install`
1011
1. `node src/main.js`
1112
1. To start a game, `@<your_bot_name>: Deal`

src/bot.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ class Bot {
1414
//
1515
// token - An API token from the bot integration
1616
constructor(token) {
17-
if (token === 'YOUR-TOKEN-GOES-HERE') {
18-
throw new Error('Use a valid API token!');
19-
} else {
20-
this.slack = new Slack(token, true, true);
21-
}
17+
this.slack = new Slack(token, true, true);
2218
}
2319

2420
// Public: Brings this bot online and starts handling messages sent to it.

src/main.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
require('babel/register');
22

3+
try {
4+
var fs = require('fs');
5+
var token = fs.readFileSync('token.txt', 'utf8').trim();
6+
} catch (error) {
7+
console.log("Your API token should be placed in a 'token.txt' file, which is missing.");
8+
return;
9+
}
10+
311
var Bot = require('./bot');
4-
var bot = new Bot('YOUR-TOKEN-GOES-HERE');
12+
var bot = new Bot(token);
513
bot.login();

0 commit comments

Comments
 (0)