2016-07-14 23:34:37 +02:00
|
|
|
var needle = require('needle');
|
|
|
|
|
|
|
|
var command = '!hash';
|
|
|
|
|
|
|
|
module.exports={
|
|
|
|
command: command,
|
|
|
|
init: init,
|
|
|
|
respond: respond
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function init(slackbot, channel) {
|
|
|
|
if (channel) {
|
|
|
|
setInterval(function() {
|
|
|
|
sendMiningInfo(slackbot, channel);
|
2016-07-24 04:21:41 +02:00
|
|
|
}, 6 * 60 * 60 * 1000);
|
2016-07-18 16:18:23 +02:00
|
|
|
// sendMiningInfo(slackbot, channel);
|
2016-07-14 23:34:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function respond(slackbot, data) {
|
|
|
|
var words = data.text.trim().split(' ');
|
|
|
|
|
|
|
|
if (words[0] !== command) {
|
|
|
|
// wtf?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (words.length > 1) {
|
|
|
|
// e.g. "!hash and some other words"
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendMiningInfo(slackbot, data.channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sendMiningInfo(slackbot, channel) {
|
2017-09-26 20:34:22 +02:00
|
|
|
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) {
|
2016-07-14 23:34:37 +02:00
|
|
|
if (error || response.statusCode !== 200) {
|
|
|
|
slackbot.postMessage(channel, 'Explorer API is not available');
|
|
|
|
}
|
|
|
|
else {
|
2017-09-26 20:34:22 +02:00
|
|
|
var data, hashrate = "", difficulty = "", height = "";
|
|
|
|
data = response.body;
|
|
|
|
height += data.status.height;
|
|
|
|
hashrate += data.status.hashrate;
|
|
|
|
difficulty += data.status.difficulty;
|
2016-07-14 23:34:37 +02:00
|
|
|
|
|
|
|
slackbot.postMessage(channel,
|
|
|
|
// 'Blockchain stats:\n' +
|
2017-09-26 20:34:22 +02:00
|
|
|
'Hashrate: ' + hashrate + '\n' +
|
2016-07-14 23:34:37 +02:00
|
|
|
'Difficulty: ' + difficulty + '\n' +
|
2017-09-26 20:34:22 +02:00
|
|
|
'Current block: ' + height + '\n' +
|
2016-07-14 23:34:37 +02:00
|
|
|
'_Source: https://explorer.lbry.io_'
|
2017-03-17 21:51:41 +01:00
|
|
|
, {icon_emoji: ':miner:'});
|
2016-07-14 23:34:37 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function numberWithCommas(x) {
|
|
|
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
2016-07-18 16:18:23 +02:00
|
|
|
}
|