/
streamOp.js
64 lines (58 loc) · 2.76 KB
/
streamOp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const Discord = require("discord.js");
const steem = require("steem");
const config = require("./../config.json");
const { nodes } = require("./../nodes");
var bot = new Discord.Client({autoReconnect:true});
var content = require("./steem-module.js");
var index = 0;
bot.login(config.token)
function stream() {
steem.api.setOptions({ url: nodes[index] });
return new Promise((resolve, reject) => {
console.log('Connected to', nodes[index]);
steem.api.streamOperations((err, operation) => {
if(err) return reject(err);
// Check all posts published on the steem blockchain
if(operation[0] == "comment" && operation[1].parent_author == "") {
let data = JSON.parse(operation[1].json_metadata),
tag = data.tags;
if(typeof tag != "undefined" ) {
if(tag.indexOf(config.principalTag) != (-1)) {
let author = operation[1].author,
permlink = operation[1].permlink;
for (v in config.altTags) {
if(tag.indexOf(v) != (-1)) {
content.getContent(author, permlink,config.altTags[v]);
}
}
content.getContent(author, permlink,config.principalChan);
}
}
} else if(operation[0] == "vote") { // Check all votes from steem blockchain
let voter = operation[1].voter,
author = operation[1].author,
permlink = operation[1].permlink,
weight = operation[1].weight / 100;
if(voter == config.trackerVoter) {
steem.api.getContent(author,permlink, function(err,res) {
let data = JSON.parse(res.json_metadata)
tag = data.tags,
embed = new Discord.RichEmbed();
embed.setTitle("@" + config.trackerVoter + " voted for @" + author)
.setDescription("Link : " + "https://busy.org/@" + author + "/" + permlink)
.setFooter("Weight vote : " + weight + "%")
.setTimestamp()
if(typeof tag != "undefined" && tag.indexOf(config.tagTrackerVoter) != (-1)) {
bot.channels.get(config.maintenance).send({embed});
}
});
}
}// End if vote
});
}).catch(err => {
console.log('Stream error:', err.message, 'with', nodes[index]);
index = ++index === nodes.length ? 0 : index;
stream();
});
}
exports.stream = stream;