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-09-08 23:54:48 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2016-07-14 23:34:37 +02:00
|
|
|
|
2017-02-02 23:52:24 +01:00
|
|
|
['SLACK_TOKEN', 'RPCUSER', 'RPCPASSWORD', 'MONGODB_URL'].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-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 hashbot = require('./bots/hashbot');
|
2016-07-14 23:34:37 +02:00
|
|
|
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);
|
2016-07-14 23:34:37 +02:00
|
|
|
|
2017-06-14 18:29:12 +02:00
|
|
|
var pricebot = require('./bots/pricebot');
|
|
|
|
pricebot.init(process.env.MARKET_TRADING_CHANNEL);
|
|
|
|
|
2017-06-15 19:14:04 +02:00
|
|
|
var modbot = require('./bots/modbot');
|
|
|
|
modbot.init(process.env.MONGODB_URL, process.env.SLACK_TOKEN, slackbot);
|
|
|
|
|
2016-07-14 23:34:37 +02:00
|
|
|
slackbot.on('start', function() {
|
|
|
|
slackbot.on('message', function(data) {
|
2017-06-15 19:14:04 +02:00
|
|
|
modbot.check(slackbot,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-08 23:55:03 +02:00
|
|
|
// gifbot.handle_msg(data.text, data.channel);
|
2016-09-05 20:54:34 +02:00
|
|
|
|
2016-07-14 23:34:37 +02:00
|
|
|
var command = data.text.trim().split(' ')[0];
|
|
|
|
|
2017-03-17 21:21:44 +01:00
|
|
|
if (command === '!help') {
|
|
|
|
var helpMsg = "I'm Wunderbot, LBRY's slackbot. Here's what I can do:\n" +
|
2017-03-17 21:26:19 +01:00
|
|
|
'`!help` shows this message\n' +
|
2017-06-19 21:30:01 +02:00
|
|
|
'`!tip` sends LBC tips to others, and withdraws and deposits credits into the your tipping wallet *(now handled by <@tipbot>)*\n' +
|
2017-03-17 21:26:19 +01:00
|
|
|
'`!hash` reports on the LBRY blockchain\n' +
|
2017-03-17 21:27:17 +01:00
|
|
|
'_type any of the above commands for more info_\n' +
|
|
|
|
'\n' +
|
|
|
|
'I also update <#C266N3RMM|content> anytime new content is published on LBRY\n' +
|
2017-03-17 21:21:44 +01:00
|
|
|
'\n' +
|
2017-03-17 21:26:19 +01:00
|
|
|
'My code is at https://github.com/lbryio/lbry-wunderbot. I love learning new tricks.\n';
|
2017-03-17 21:21:44 +01:00
|
|
|
|
2017-03-17 21:51:41 +01:00
|
|
|
slackbot.postMessage(data.channel, helpMsg, {icon_emoji: ':bulb:'});
|
2017-03-17 21:21:44 +01:00
|
|
|
}
|
|
|
|
|
2016-07-14 23:34:37 +02:00
|
|
|
if (command === hashbot.command) {
|
|
|
|
hashbot.respond(slackbot, data);
|
|
|
|
}
|
|
|
|
|
2017-06-19 21:20:12 +02:00
|
|
|
if (command === '!tip' && data.channel.startsWith("D")) {
|
2017-06-19 21:26:51 +02:00
|
|
|
var tipMsg = 'Sorry, tipping is now handled by <@tipbot>\n';
|
2017-06-19 21:20:12 +02:00
|
|
|
slackbot.postMessage(data.channel, tipMsg, {icon_emoji: ':bulb:'});
|
2016-07-14 23:34:37 +02:00
|
|
|
}
|
2017-06-14 18:29:12 +02:00
|
|
|
|
|
|
|
if (command === pricebot.command) {
|
|
|
|
pricebot.respond(slackbot, data);
|
|
|
|
}
|
2016-07-14 23:34:37 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|