2016-07-14 23:34:37 +02:00
|
|
|
var SlackBot = require('slackbots');
|
2016-08-08 21:46:54 +02:00
|
|
|
var request = require('request');
|
2016-07-14 23:34:37 +02:00
|
|
|
|
2016-09-08 18:47:31 +02:00
|
|
|
['SLACK_TOKEN', 'RPCUSER', 'RPCPASSWORD', 'IMGUR_CLIENT_ID'].forEach(function(envVar) {
|
2016-07-14 23:34:37 +02:00
|
|
|
if (!process.env[envVar]) {
|
|
|
|
throw new Error(envVar + ' env var required');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var slackbot = new SlackBot({
|
|
|
|
token: process.env.SLACK_TOKEN,
|
|
|
|
name: 'wunderbot'
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-08-16 18:39:24 +02:00
|
|
|
|
|
|
|
function sendWelcomeMessage(usertowelcome) {
|
|
|
|
request('https://raw.githubusercontent.com/lbryio/lbry.io/master/posts/other/slack-greeting.md', function (error, response, body) {
|
|
|
|
if (!error && response.statusCode == 200) {
|
|
|
|
slackbot.postMessage(usertowelcome, body);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var tipbot = require('./bots/tipbot');
|
2016-07-14 23:34:37 +02:00
|
|
|
tipbot.init(process.env.RPCUSER, process.env.RPCPASSWORD);
|
|
|
|
|
2016-08-16 18:39:24 +02:00
|
|
|
var hashbot = require('./bots/hashbot');
|
2016-07-14 23:34:37 +02:00
|
|
|
hashbot.init(slackbot, process.env.MINING_CHANNEL);
|
|
|
|
|
2016-09-05 20:54:34 +02:00
|
|
|
var gifbot = require('./bots/gifbot');
|
|
|
|
gifbot.init(slackbot, process.env.IMGUR_CLIENT_ID);
|
2016-07-14 23:34:37 +02:00
|
|
|
|
|
|
|
slackbot.on('start', function() {
|
|
|
|
slackbot.on('message', function(data) {
|
2016-08-16 18:39:24 +02:00
|
|
|
if (data.type == 'team_join') {
|
|
|
|
setTimeout(function() { sendWelcomeMessage(data.user.id); }, 2000); //Delay because of slow slack api updates which sometimes does not send msg.
|
2016-08-08 21:46:54 +02:00
|
|
|
}
|
2016-07-14 23:34:37 +02:00
|
|
|
if (data.text) {
|
2016-09-05 20:54:34 +02:00
|
|
|
gifbot.handle_msg(data.text, data.channel);
|
|
|
|
|
2016-07-14 23:34:37 +02:00
|
|
|
var command = data.text.trim().split(' ')[0];
|
|
|
|
|
|
|
|
if (command === hashbot.command) {
|
|
|
|
hashbot.respond(slackbot, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command === tipbot.command) {
|
|
|
|
tipbot.respond(slackbot, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|