lbry-tipbot/app.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

var SlackBot = require('slackbots');
var request = require('request');
2016-09-08 23:54:48 +02:00
var fs = require('fs');
var path = require('path');
2017-02-02 23:52:24 +01:00
['SLACK_TOKEN', 'RPCUSER', 'RPCPASSWORD', 'MONGODB_URL'].forEach(function (envVar) {
if (!process.env[envVar]) {
throw new Error(envVar + ' env var required');
}
});
var slackbot = new SlackBot({
token: process.env.SLACK_TOKEN,
name: 'wunderbot'
});
2016-09-08 23:54:48 +02:00
function sendWelcomeMessage(user) {
fs.readFile(path.join(path.dirname(require.main.filename), 'slack-greeting.md'), {encoding: 'utf-8'}, function (error, data) {
if (!error) {
slackbot.postMessage(user, data);
2016-08-16 18:39:24 +02:00
}
});
};
var tipbot = require('./bots/tipbot');
tipbot.init(process.env.RPCUSER, process.env.RPCPASSWORD);
2016-08-16 18:39:24 +02:00
var hashbot = require('./bots/hashbot');
hashbot.init(slackbot, process.env.MINING_CHANNEL);
2017-02-02 23:52:24 +01:00
var claimbot = require('./bots/claimbot');
claimbot.init(slackbot, process.env.CLAIMS_CHANNEL, process.env.RPCUSER, process.env.RPCPASSWORD, process.env.MONGODB_URL);
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.
}
if (data.text) {
2016-09-08 23:55:03 +02:00
// gifbot.handle_msg(data.text, data.channel);
2016-09-05 20:54:34 +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);
}
}
});
});