-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
68 lines (61 loc) · 1.89 KB
/
bot.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
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
// ========================================
// ___ _ ___ _
// / _ (_)___ ___ ___ / __\ ___ | |_
// / /_)/ / __|/ __/ _ \ /__\/// _ \| __|
// / ___/| \__ \ (_| (_) / \/ \ (_) | |_
// \/ |_|___/\___\___/\_____/\___/ \__|
// ========================================
// Please enjoy responsibly.
// Require core Botkit library, because we need to do things with it (obviously)
var Botkit = require('botkit');
if(process.env.MONGODB_URI) {
var mongoStorage = require('botkit-storage-mongo')({ mongoUri: process.env.MONGODB_URI });
}
// Set botConfig variable
var botConfig = {};
if(process.env.DEVELOPMENT) {
botConfig = {
debug: true,
logLevel: 7,
storage: mongoStorage
};
} else {
botConfig = {
debug: false,
storage: mongoStorage
};
}
// Set the bot controller as a global variable which can be accessed in
// any file without having to pass it through anything.
global.piscobot = Botkit.slackbot(botConfig);
// Set a global `botHelp` array that can be modified by any script
// to be able to include itself in the `help` command.
global.botHelp = [];
// If there's a SLACK_API_TOKEN,
if(process.env.SLACK_API_TOKEN) {
// Connect the bot to Slack's RTM API.
global.piscobot.spawn({
// Grab the token from the currently running process.
token: process.env.SLACK_API_TOKEN
}).startRTM();
} else {
// Otherwise exit cleanly.
Botkit.log(
'WARNING: No SLACK_API_TOKEN present, can\'t connect to Slack!'
);
Botkit.log(
'NOTICE: Exiting app because we can\'t do anything without a token.'
);
process.end(0);
}
/* eslint-disable */
// Disable ESLint because this is necessary for the app to work.
// Load all of the scripts into the bot.
var scripts = require('require-all')({
dirname: __dirname + '/modules',
recursive: true
});
// Start up our webserver.
var helpers = require('./helpers');
/* eslint-enable */