Merge pull request #10 from lbryio/revert-9-metadata-fix

Revert "Fallback solution as proposed in pull #7"
This commit is contained in:
Fillerino 2017-06-15 10:07:01 +02:00 committed by GitHub
commit 096d3513de
2 changed files with 12 additions and 41 deletions

View file

@ -5,8 +5,7 @@ var mongo;
var slackbot; var slackbot;
var channel; var channel;
var moment = require('moment'); var moment = require('moment');
var request = require('request'); const request = require("request");
var sleep = require('sleep');
module.exports = { module.exports = {
init: init, init: init,
@ -91,7 +90,6 @@ function announceNewClaims() {
function announceClaimsLoop(block, lastBlock, currentHeight) { function announceClaimsLoop(block, lastBlock, currentHeight) {
// console.log('Doing block ' + block) // console.log('Doing block ' + block)
let claimsFound = 0;
return lbryCall('getblockhash', block) return lbryCall('getblockhash', block)
.then(function (blockHash) { .then(function (blockHash) {
return lbryCall('getblock', blockHash); return lbryCall('getblock', blockHash);
@ -104,12 +102,7 @@ function announceClaimsLoop(block, lastBlock, currentHeight) {
return !!c; return !!c;
}); });
console.log('Found ' + claims.length + ' claims in ' + block); console.log('Found ' + claims.length + ' claims in ' + block);
claimsFound = claims.length;
return Promise.all(claims.map(function (claim) { return Promise.all(claims.map(function (claim) {
//slack has a rate limit. to avoid hitting it we must have a small delay between each message
//if claims were found in this block, then we wait, otherwise we don't
if (claimsFound > 0)
sleep.msleep(300);
return announceClaim(claim, block, currentHeight); return announceClaim(claim, block, currentHeight);
})); }));
}) })
@ -135,45 +128,27 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
request(options, function (error, response, body) { request(options, function (error, response, body) {
if (error) throw new Error(error); if (error) throw new Error(error);
try {
console.log(body);
let claimData = null;
let channelName = null;
try {
body = JSON.parse(body); body = JSON.parse(body);
if (body.hasOwnProperty('value') && body.value.hasOwnProperty('stream') && body.value.stream.hasOwnProperty('metadata')) { try {
claimData = body.value.stream.metadata; let claimData = body.value.stream.metadata;
channelName = (body.hasOwnProperty('channel_name') ? body['channel_name'] : null); let channelName = (body.hasOwnProperty('channel_name') ? body['channel_name'] : null);
} //claimData = JSON.parse(body).stream.metadata;
} //console.log(JSON.stringify(claimData));
catch (e) {
console.error(e);
}
return Promise.all([ return Promise.all([
lbryCall('getvalueforname', claim['name']), lbryCall('getvalueforname', claim['name']),
lbryCall('getclaimsforname', claim['name']), lbryCall('getclaimsforname', claim['name']),
]) ])
.then(function ([currentWinningClaim, claimsForName]) { .then(function ([currentWinningClaim, claimsForName]) {
//console.log(JSON.stringify(claimData)); //console.log(JSON.stringify(claimData));
let value = null; let value = claimData;
if (claimData !== null)
value = claimData;
else {
try {
value = JSON.parse(claim['value']);
} catch (e) { }
}
const text = []; const text = [];
if (value) { if (value) {
/*if (channelName) { if (channelName) {
text.push("Channel: lbry://" + channelName); text.push("Channel: lbry://" + channelName);
} }
else*/ else if (value['author']) {
if (value['author']) {
text.push("author: " + value['author']); text.push("author: " + value['author']);
} }
if (value['description']) { if (value['description']) {
@ -186,15 +161,12 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
if (value['nsfw']) { if (value['nsfw']) {
text.push("*Warning: Adult Content*"); text.push("*Warning: Adult Content*");
} }
//"fee":{"currency":"LBC","amount":186,"version":"_0_0_1","address":"bTGoFCakvQXvBrJg1b7FJzombFUu6iRJsk"}
if (value['fee']) { if (value['fee']) {
const fees = []; const fees = [];
text.push("Price: " + value['fee'].amount + " *" + value['fee'].currency + '*'); for (var key in value['fee']) {
/*for (var key in value['fee']) {
fees.push(value['fee'][key]['amount'] + ' ' + key); fees.push(value['fee'][key]['amount'] + ' ' + key);
} }
text.push(fees.join(', '));*/ text.push(fees.join(', '));
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "hashbot", "name": "hashbot",
"version": "1.0.2", "version": "1.0.1",
"description": "A bot for slack wich displays lbrys current hashrate via the open api.", "description": "A bot for slack wich displays lbrys current hashrate via the open api.",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
@ -11,7 +11,6 @@
"needle": "^1.0.0", "needle": "^1.0.0",
"request": "^2.81.0", "request": "^2.81.0",
"slackbots": "^0.5.1", "slackbots": "^0.5.1",
"sleep": "^5.1.1",
"xmlhttprequest": "1.8.0" "xmlhttprequest": "1.8.0"
}, },
"devDependencies": {}, "devDependencies": {},