mirror of
https://github.com/LBRYFoundation/lbry-tipbot.git
synced 2025-08-23 16:57:24 +00:00
Pushed the main files.
This commit is contained in:
commit
7bcf5c15b8
3 changed files with 77 additions and 0 deletions
53
bot.js
Normal file
53
bot.js
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
//Please note that this was quickly made and it just works, if you would like to improve it just do a pull and i´ll check it //Fillerino
|
||||||
|
var SlackBot = require('slackbots');
|
||||||
|
var needle = require('needle');
|
||||||
|
|
||||||
|
var bot = new SlackBot({
|
||||||
|
token: '>>>>TOKEN<<<<', // Add a bot https://my.slack.com/services/new/bot and put the token
|
||||||
|
name: 'hashbot'
|
||||||
|
});
|
||||||
|
|
||||||
|
function numberWithCommas(x) {
|
||||||
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bot.on('start', function() {
|
||||||
|
// more information about additional params https://api.slack.com/methods/chat.postMessage
|
||||||
|
bot.on('message', function(data) {
|
||||||
|
msg = data.text;
|
||||||
|
if (msg.indexOf('!hash') >= 0) {
|
||||||
|
getdata();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getdata() {
|
||||||
|
needle.get('https://explorer.lbry.io/api/getnetworkhashps', function(error, response) {
|
||||||
|
if (!error && response.statusCode == 200)
|
||||||
|
console.log(response.body);
|
||||||
|
currenthash = response.body / 1000000000
|
||||||
|
//Gets current Diff
|
||||||
|
needle.get('https://explorer.lbry.io/api/getdifficulty', function(error, response) {
|
||||||
|
if (!error && response.statusCode == 200)
|
||||||
|
console.log(response.body);
|
||||||
|
currentdiff = numberWithCommas(Math.round(response.body));
|
||||||
|
//Gets current block
|
||||||
|
needle.get('https://explorer.lbry.io/api/getblockcount', function(error, response) {
|
||||||
|
if (!error && response.statusCode == 200)
|
||||||
|
console.log(response.body);
|
||||||
|
var currentblock = numberWithCommas(response.body);
|
||||||
|
//bot.postMessageToChannel('mining', '*Current stats: *' + os.EOL + '*Hashrate: ' + Math.round(currenthash) + ' GH/s*' + os.EOL + '*Difficulty: ' + currentdiff + os.EOL + '*' + '*Current block: ' + currentblock + os.EOL + '*' + '_You can see this data and much more on the official explorer https://explorer.lbry.io!_');
|
||||||
|
bot.postMessageToChannel('mining', '*Current stats:*\n' + '*Hashrate: ' + Math.round(currenthash) + ' GH/s*\n' + '*Difficulty: ' + currentdiff + '*\n' + '*Current block: ' + currentblock + '*\n' + '_You can see this data and much more on the official explorer https://explorer.lbry.io!_');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Hour interval posting
|
||||||
|
setInterval(getdata, 3600000);
|
||||||
|
getdata();
|
||||||
|
//
|
||||||
|
});
|
24
package.json
Normal file
24
package.json
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"name": "hashbot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A bot for slack wich displays lbrys current hashrate via the open api.",
|
||||||
|
"main": "bot.js",
|
||||||
|
"dependencies": {
|
||||||
|
"needle": "^1.0.0",
|
||||||
|
"slackbots": "^0.5.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lbryio/hashbot.git"
|
||||||
|
},
|
||||||
|
"author": "Fillerino",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/lbryio/hashbot/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/lbryio/hashbot#readme"
|
||||||
|
}
|
0
readme.md
Normal file
0
readme.md
Normal file
Loading…
Add table
Reference in a new issue