fixed claimbot

updated packages
added configs
formatted configs
This commit is contained in:
Niko Storni 2017-11-14 00:25:04 +01:00
parent aa6a233317
commit d01777b39a
3 changed files with 1993 additions and 115 deletions

View file

@ -32,7 +32,7 @@ function init(discordBot_, mongodburl) {
lbry = new bitcoin.Client(config.get("lbrycrd")); lbry = new bitcoin.Client(config.get("lbrycrd"));
console.log("Activating claimbot"); console.log("Activating claimbot");
discordBot.channels.get("377938982111019010").send("activating claimbot"); discordBot.channels.get(channels[0]).send("activating claimbot");
setInterval(function() { setInterval(function() {
announceNewClaims(); announceNewClaims();
@ -55,9 +55,6 @@ function announceNewClaims() {
Promise.all([getLastBlock(), lbryCall("getinfo")]) Promise.all([getLastBlock(), lbryCall("getinfo")])
.then(function([lastProcessedBlock, currentBlockInfo]) { .then(function([lastProcessedBlock, currentBlockInfo]) {
const currentHeight = currentBlockInfo["blocks"]; const currentHeight = currentBlockInfo["blocks"];
// console.log('Checking for new blocks');
if (lastProcessedBlock === null) { if (lastProcessedBlock === null) {
console.log( console.log(
"First run. Setting last processed block to " + "First run. Setting last processed block to " +
@ -87,7 +84,6 @@ function announceNewClaims() {
} }
function announceClaimsLoop(block, lastBlock, currentHeight) { function announceClaimsLoop(block, lastBlock, currentHeight) {
// console.log('Doing block ' + block)
let claimsFound = 0; let claimsFound = 0;
return lbryCall("getblockhash", block) return lbryCall("getblockhash", block)
.then(function(blockHash) { .then(function(blockHash) {
@ -129,7 +125,6 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
console.log(claim); console.log(claim);
let options = { let options = {
method: "GET", method: "GET",
//url: 'https://explorer.lbry.io/api/getclaimbyid/' + claim['claimId']
url: "http://127.0.0.1:5000/claim_decode/" + claim["name"] url: "http://127.0.0.1:5000/claim_decode/" + claim["name"]
}; };
@ -172,9 +167,9 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
if (value) { if (value) {
/*if (channelName) { /*if (channelName) {
text.push("Channel: lbry://" + channelName); text.push("Channel: lbry://" + channelName);
} }
else*/ else*/
console.log(value); console.log(value);
if (value["author"]) { if (value["author"]) {
text.push("author: " + value["author"]); text.push("author: " + value["author"]);
@ -200,10 +195,6 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
value["fee"].currency + value["fee"].currency +
"*" "*"
); );
/*for (var key in value['fee']) {
fees.push(value['fee'][key]['amount'] + ' ' + key);
}
text.push(fees.join(', '));*/
} }
if (!claim["is controlling"]) { if (!claim["is controlling"]) {
@ -249,65 +240,6 @@ function announceClaim(claim, claimBlockHeight, currentHeight) {
discordPost(text, richEmbeded); discordPost(text, richEmbeded);
} }
/*
if (!claim['is controlling']) {
// the following is based on https://lbry.io/faq/claimtrie-implementation
const lastTakeoverHeight = claimsForName['nLastTakeoverHeight'],
maxDelay = 4032, // 7 days of blocks at 2.5min per block
activationDelay = Math.min(maxDelay, Math.floor((claimBlockHeight - lastTakeoverHeight) / 32)),
takeoverHeight = claimBlockHeight + activationDelay,
secondsPerBlock = 161, // in theory this should be 150, but in practice its closer to 161
takeoverTime = Date.now() + ((takeoverHeight - currentHeight) * secondsPerBlock * 1000);
text.push('Takes effect on approx. *' + moment(takeoverTime, 'x').format('MMMM Do [at] HH:mm [UTC]') + '* (block ' + takeoverHeight + ')');
}
const richEmbeded = {
author: {
name: value['author'] | 'Anonymous',
url: 'http://open.lbry.io/' + claim['name'],
icon_url: 'http://barkpost-assets.s3.amazonaws.com/wp-content/uploads/2013/11/3dDoge.gif'
},
title: "[lbry://" + (channelName ? channelName + '/' : '') + claim['name'] + '](http://open.lbry.io/' + claim['name'] + ')',
color: "#155b4a",
description: escapeSlackHtml(text.join("\n")),
footer: "Block " + claimBlockHeight + " • Claim ID " + claim['claimId'],
image: (!value['nsfw']) ? (value['thumbnail'] | '') : '',
thumbnail: (!value['nsfw']) ? (value['thumbnail'] | '') : '',
url: 'http://open.lbry.io/' + claim['name'],
}
const attachment = {
"fallback": "New claim for lbry://" + claim['name'],
"color": "#155b4a",
// "pretext": "New claim in block " + claimBlockHeight,
// "author_name": 'lbry://' + claim['name'],
// "author_link": 'lbry://' + claim['name'],
// "author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "lbry://" + (channelName ? channelName + '/' : '') + claim['name'], //escapeSlackHtml(value['title']),
"title_link": "lbry://" + (channelName ? channelName + '/' : '') + claim['name'],
"text": escapeSlackHtml(text.join("\n")),
// "fields": [],
// "image_url": value['nsfw'] ? null : value['thumbnail'],
// "thumb_url": (!value || value['nsfw']) ? null : value['thumbnail'],
"unfurl_links": false,
"unfurl_media": false,
"link_names": false,
"parse": "none",
"footer": "Block " + claimBlockHeight + " • Claim ID " + claim['claimId'],
"mrkdwn_in": ['text'],
};
if (value) {
attachment['fallback'] += (': "' + value['title'] + '" by ' + value['author']);
attachment['author_name'] = 'lbry://' + (channelName ? channelName + '/' : '') + claim['name'];
attachment['author_link'] = 'lbry://' + (channelName ? channelName + '/' : '') + claim['name'];
attachment['title'] = escapeSlackHtml(value['title']);
if (!value['nsfw']) {
attachment['thumb_url'] = value['thumbnail'];
}
}
discordPost(text, richEmbeded);*/
//discordPost('', { icon_emoji: ':bellhop_bell:', attachments: [attachment] });
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -372,22 +304,10 @@ function setLastBlock(block) {
} }
function discordPost(text, params) { function discordPost(text, params) {
//tmpdata = params.attachments[0];
let richEmbeded = new Discord.RichEmbed(params); let richEmbeded = new Discord.RichEmbed(params);
/*richEmbeded.setAuthor(tmpdata.author_name, tmpdata.thumb_url, 'http://open.lbry.io/' + tmpdata.title);
richEmbeded.setColor(tmpdata.color);
richEmbeded.setDescription(tmpdata.text);
richEmbeded.setTitle(tmpdata.title);
richEmbeded.setURL('http://open.lbry.io/' + tmpdata.title);
richEmbeded.setFooter(tmpdata.footer);*/
//console.log(params);
channels.forEach(channel => { channels.forEach(channel => {
discordBot.channels.get(channel).send("", richEmbeded); discordBot.channels.get(channel).send("", richEmbeded);
}); });
/*discordBot.postMessage(channel, text, params).fail(function (value) {
console.log('FAILED TO SLACK to ' + channel + '. Text: "' + text + '". Params: ' + JSON.stringify(params) + "\nResponse: " + JSON.stringify(value));
});*/
} }
function lbryCall(...args) { function lbryCall(...args) {

View file

@ -1,45 +1,92 @@
{ {
// Bot configuration // Bot configuration
"bot": { "bot": {
"token":"discordbottoken", "token": "discordbottoken",
"prefix": "!", "prefix": "!",
"debug": false "debug": false
}, },
"lbrycrd": { "lbrycrd": {
"port": 9245, "port": 9245,
"user": "lbry", "user": "user",
"pass": "lbry" "pass": "password"
}, },
//define channels for Commands.js usage //define channels for Commands.js usage
"Channels":{ "Channels": {
"verification": "363050496023592961", "verification": "363050496023592961",
"mining": "363049669636390913", "mining": "363049669636390913",
"random": "363084227518136322" "random": "363084227518136322",
"content": "377938982111019010"
}, },
"speechbot":{ "speechbot": {
"channels": ["363089721313722387","363085078403874823","363086945976320010","363086925428555776","363086752518242308","369896313082478594","363087606239461377","363088045366312962","363084227518136322","363084262028607488","371620338263523328"], // Channels speech bot is allowed to post in "channels": [
"mainchannel": "363085078403874823" // Main Speech Bot channel for directing with help message "363089721313722387",
"363085078403874823",
"363086945976320010",
"363086925428555776",
"363086752518242308",
"369896313082478594",
"363087606239461377",
"363088045366312962",
"363084227518136322",
"363084262028607488",
"371620338263523328"
], // Channels speech bot is allowed to post in
"mainchannel": "363085078403874823" // Main Speech Bot channel for directing with help message
}, },
"pricebot":{ "pricebot": {
"channels": ["363050205043621908","369896313082478594","371620338263523328"], // Chanels price bot is allowed to post in "channels": [
"mainchannel": "363050205043621908" // Main Price Bot channel for directing with help message "363050205043621908",
"369896313082478594",
"371620338263523328"
], // Chanels price bot is allowed to post in
"mainchannel": "363050205043621908" // Main Price Bot channel for directing with help message
}, },
"gitrelease":{ "gitrelease": {
"channel": "370779899650375681" // Channel to send release info to using <!releasenotes post> "channel": "370779899650375681" // Channel to send release info to using <!releasenotes post>
}, },
"spamdetection":{ "spamdetection": {
"channels": ["363089721313722387","363044238486798336","363086719391629326","363044275363119105","363044260938776576","372067478542745601","369896313082478594","371620338263523328"], // Channels excluded from Spam Detection "channels": [
"users" : ["244245498746241025"] // Users to exclude from Spam Detection (include other bots here) "363089721313722387",
"363044238486798336",
"363086719391629326",
"363044275363119105",
"363044260938776576",
"372067478542745601",
"369896313082478594",
"371620338263523328"
], // Channels excluded from Spam Detection
"users": [
"244245498746241025"
] // Users to exclude from Spam Detection (include other bots here)
}, },
"hashbot":{ "hashbot": {
"channels": ["363049669636390913","369896313082478594","371620338263523328"], // Channels Hash Bot is allowed to post in "channels": [
"mainchannel" : "363049669636390913" // Main Hash Bot channel for directing with help message "363049669636390913",
"369896313082478594",
"371620338263523328"
], // Channels Hash Bot is allowed to post in
"mainchannel": "363049669636390913" // Main Hash Bot channel for directing with help message
}, },
"statsbot":{ "statsbot": {
"channels": ["363050205043621908","369896313082478594","371620338263523328"], // Channels Stats Bot is allowed to post in "channels": [
"mainchannel" : "363050205043621908" // Main Stats Bot channel for directing with help message "363050205043621908",
"369896313082478594",
"371620338263523328"
], // Channels Stats Bot is allowed to post in
"mainchannel": "363050205043621908" // Main Stats Bot channel for directing with help message
}, },
"rolelist":{ "rolelist": {
"allowedroles": ["Role1","Role2"] "allowedroles": [
"Role1",
"Role2"
]
},
"claimbot": {
"channels": [
"377938982111019010"
]
},
"mongodb": {
"url": "mongodb://HOST:PORT/DATABASE"
} }
} }

1911
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff