forked from andrewjkerr/hackathon-mentor-request-slackbot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.js
55 lines (41 loc) · 1.4 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
/*
testbot. whoa.
now with 100% more Tumblrn magic.
*/
// oops
var config_functions = require('./config_functions.js');
var utils = require('./utils.js');
var slack_functions = require('./slack_functions.js');
var bot_functions = require('./bot_functions.js');
config_functions.config_check();
var config_file = config_functions.config_arg_parse();
// Set up variables
var config = require(config_file);
// primary bot config
global.bot_name = config.bot_name;
global.bot_trigger = config.bot_trigger;
global.teams = config.teams;
global.admins = config.admins;
// TO-DO - make this automatically generated from teams
global.available = config.mentors;
// Dupe mentors to check against later
global.mentors = config.mentors.slice(0);
// Init Slack
global.slack = slack_functions.init(config.api_token);
// Add a message handler
slack.on('message', function(message) {
if (message.type == 'message') {
// if there is no user, then it's probably not something we need to worry about
if (message.user == undefined) {
return;
}
// send the incoming message off to be parsed + responded to
bot_functions.handle_message(message);
} else {
return; // do nothing with other types of messages for now
}
});
// add a trim() method for strings
String.prototype.trim = function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };
// actually log in and connect!
slack.login();