/
index.js
56 lines (45 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var BotEnvironment = function(props) {
this.default_props = {
auth_file: 'auth.js'
};
this.props = _.assignInWith({}, props, this.default_props , (o,s) => { return _.isUndefined(o) ? s : o; });
if(this.props.auth_file[0] !== '/') {
this.props.auth_file = process.cwd() + '/' + this.props.auth_file
}
this.auth = {};
var auth;
if(fs.existsSync(this.props.auth_file)) {
auth = require(this.props.auth_file);
} else {
console.log('Did not find ' + this.props.auth_file + ' (bot may not run properly).');
}
for (var key in auth) {
this.auth[key] = auth[key];
}
// Load keys from environment variables if they are missing in file:
if(!_.has(auth, 'consumer_key')) {
this.auth['consumer_key'] = process.env.CONSUMER_KEY;
}
if(!_.has(auth, 'consumer_secret')) {
this.auth['consumer_secret'] = process.env.CONSUMER_SECRET;
}
if(!_.has(auth, 'access_token_key')) {
this.auth['access_token_key'] = process.env.ACCESS_TOKEN_KEY;
}
if(!_.has(auth, 'access_token_secret')) {
this.auth['access_token_secret'] = process.env.ACCESS_TOKEN_SECRET;
}
console.log('Environment has been set up.')
};
BotEnvironment.prototype.getEnvironment = function() {
return {
consumer_key: this.auth['consumer_key'],
consumer_secret: this.auth['consumer_secret'],
access_token_key: this.auth['access_token_key'],
access_token_secret: this.auth['access_token_secret']
};
}
module.exports = BotEnvironment;