mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
fixed up bot
This commit is contained in:
parent
cc19357103
commit
27be6dca6f
3 changed files with 56 additions and 48 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
26
README.md
26
README.md
|
@ -1,13 +1,21 @@
|
||||||
#Hashbot
|
# LBRY Hashbot
|
||||||
#####Hashbot for LBRYs slack, sends out messages about the current mining process every hour or
|
|
||||||
#####when the command !hash gets detected.
|
Hashbot for [LBRY's Slack](https://slack.lbry.io). Posts mining info to #mining every hour and anytime someone says `!hash`.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
- node
|
||||||
|
- npm > 0.12.x
|
||||||
|
|
||||||
|
Create a bot and get the bot's API Token: https://YOURSLACK.slack.com/apps/manage/custom-integrations
|
||||||
|
|
||||||
|
Replace `<your-slack-token>` below with your api token.
|
||||||
|
|
||||||
######Installation
|
|
||||||
**Requirements:**
|
|
||||||
**node and npm > 0.12.x**
|
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
Edit the bot.js and add api key.
|
SLACK_TOKEN=<your-slack-token> node bot.js
|
||||||
node bot.js
|
|
||||||
```
|
```
|
||||||
*Made by Fillerino for LBRYs slack, MIT Licensed so feel free to improve!*
|
|
||||||
|
Made by Fillerino for LBRYs slack. MIT Licensed so feel free to improve!
|
67
bot.js
67
bot.js
|
@ -1,9 +1,14 @@
|
||||||
//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 SlackBot = require('slackbots');
|
||||||
var needle = require('needle');
|
var needle = require('needle');
|
||||||
|
|
||||||
|
var SLACK_TOKEN = process.env.SLACK_TOKEN;
|
||||||
|
|
||||||
|
if (!SLACK_TOKEN) {
|
||||||
|
throw new Error('SLACK_TOKEN env var required');
|
||||||
|
}
|
||||||
|
|
||||||
var bot = new SlackBot({
|
var bot = new SlackBot({
|
||||||
token: '>>>>TOKEN<<<<', // Add a bot https://my.slack.com/services/new/bot and put the token
|
token: SLACK_TOKEN,
|
||||||
name: 'hashbot'
|
name: 'hashbot'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,43 +16,37 @@ function numberWithCommas(x) {
|
||||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getData() {
|
||||||
|
needle.get('https://explorer.lbry.io/api/getmininginfo', function(error, response) {
|
||||||
|
// if (!error && response.statusCode == 200) {
|
||||||
|
// console.log(response.body);
|
||||||
|
// }
|
||||||
|
|
||||||
|
var data = response.body,
|
||||||
|
hashrate = Math.round(data.networkhashps / 1000000000),
|
||||||
|
difficulty = numberWithCommas(Math.round(data.difficulty)),
|
||||||
|
block = numberWithCommas(data.blocks);
|
||||||
|
|
||||||
|
bot.postMessageToChannel('testing',
|
||||||
|
// 'Blockchain stats:\n' +
|
||||||
|
'Hashrate: ' + hashrate + ' GH/s\n' +
|
||||||
|
'Difficulty: ' + difficulty + '\n' +
|
||||||
|
'Current block: ' + block + '\n' +
|
||||||
|
'_Source: https://explorer.lbry.io_'
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bot.on('start', function() {
|
bot.on('start', function() {
|
||||||
// more information about additional params https://api.slack.com/methods/chat.postMessage
|
// more information about additional params https://api.slack.com/methods/chat.postMessage
|
||||||
bot.on('message', function(data) {
|
bot.on('message', function(data) {
|
||||||
msg = data.text;
|
if (data.text && data.text.trim() === '!hash') {
|
||||||
if (msg.indexOf('!hash') >= 0) {
|
getData();
|
||||||
getdata();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getdata() {
|
// Post every hour
|
||||||
needle.get('https://explorer.lbry.io/api/getnetworkhashps', function(error, response) {
|
setInterval(getData, 3600000);
|
||||||
if (!error && response.statusCode == 200)
|
getData();
|
||||||
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();
|
|
||||||
//
|
|
||||||
});
|
});
|
Loading…
Add table
Reference in a new issue