mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-09-03 20:35:12 +00:00
add channel checks
This commit is contained in:
parent
929533d142
commit
d70164716b
1 changed files with 36 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
var needle = require('needle');
|
||||
|
||||
var ChannelID = "363049669636390913"
|
||||
exports.commands = [
|
||||
"hash" // command that is in this file, every command needs it own export as shown below
|
||||
]
|
||||
|
@ -11,7 +11,28 @@ exports.custom = [
|
|||
exports.timedhash = function(bot) {
|
||||
setInterval(function() {
|
||||
sendMiningInfo(bot, msg);
|
||||
}, 6 * 60 * 60 * 1000);
|
||||
}, 60 * 60 * 1000);
|
||||
|
||||
function sendMiningInfo(bot, msg) {
|
||||
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
bot.channels.get(ChannelID).send('Explorer API is not available');
|
||||
} else {
|
||||
var data, hashrate = "", difficulty = "", height = "";
|
||||
data = response.body;
|
||||
height += data.status.height;
|
||||
hashrate += data.status.hashrate;
|
||||
difficulty += data.status.difficulty;
|
||||
bot.channels.get(ChannelID).send(
|
||||
// 'Blockchain stats:\n' +
|
||||
'Hashrate: ' + hashrate + '\n' +
|
||||
'Difficulty: ' + difficulty + '\n' +
|
||||
'Current block: ' + height + '\n' +
|
||||
'_Source: https://explorer.lbry.io_'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,12 +40,15 @@ exports.hash = {
|
|||
usage: "",
|
||||
description: 'Displays current Hashrate of Network',
|
||||
process: function(bot,msg){
|
||||
|
||||
var command = '!hash';
|
||||
sendMiningInfo(bot, msg);
|
||||
|
||||
|
||||
function sendMiningInfo(bot, msg) {
|
||||
if(!inPrivateOrBotSandbox(msg)){
|
||||
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to hash bot.');
|
||||
return;
|
||||
}
|
||||
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('Explorer API is not available');
|
||||
|
@ -47,10 +71,18 @@ function sendMiningInfo(bot, msg) {
|
|||
});
|
||||
}
|
||||
|
||||
function inPrivateOrBotSandbox(msg){
|
||||
if((msg.channel.type == 'dm') || (msg.channel.id === ChannelID)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue