forked from TelosGlobal/kickbot2
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstrut.js
114 lines (101 loc) · 2.79 KB
/
strut.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const fetch = require("node-fetch");
const axios = require("axios").default;
const apikey = process.env.TGKEY;
const debug = true;
const HyperionSocketClient = require("@eosrio/hyperion-stream-client").default;
const client = new HyperionSocketClient("https://telos.caleos.io", {
async: true,
fetch,
});
client.onConnect = () => {
client.streamActions({
contract: "eosio",
action: "unregprod",
account: "",
start_from: "2021-04-01T00:00:00.000Z",
read_until: 0,
filters: [],
});
client.streamActions({
contract: "eosio",
action: "regproducer",
account: "",
start_from: "2021-04-01T00:00:00.000Z",
read_until: 0,
filters: [],
});
client.streamDeltas({
code: "eosio",
table: "producers",
scope: "eosio",
payer: "",
start_from: "2021-04-09T00:31:00.000Z",
//start_from: 0,
read_until: 0,
//read_until: '2021-03-03T02:36:00.000Z',
});
};
let producers = {};
//producers["telosglobal1"] = {
// owner: "telosglobal1",
// is_active: 1,
// missed_blocks_per_rotation: 0,
// };
let msg = 0;
let state = "";
let msgtext = "";
async function postToChannel(chat_id, text) {
if (debug) {
console.log(`Posting to ${chat_id}:\n${text}`);
return;
}
axios({
method: "post",
url: "https://api.telegram.org/" + apikey + "/sendMessage",
data: {
chat_id,
text,
},
});
}
// see 3 for handling data
client.onData = async (data, ack) => {
//console.log(data); // process incoming data, replace with your code
// console.log(data.type); // process incoming data, replace with your code
//console.log(data.content.act.name); // process incoming data, replace with your code
//console.log(data.content.producer); // process incoming data, replace with your code
// console.log(data.content.block_num); // process incoming data, replace with your code
if (data.type == "action") {
if (!producers[data.content.producer]) {
producers[data.content.producer] = {
owner: data.content.producer,
is_active: 1,
missed_blocks_per_rotation: 0,
};
}
if (data.content.act.name == "regproducer") {
await postToChannel(
"@teloskickbot",
data.content.producer.toUpperCase() +
" Registered at block " +
data.content.block_num
);
}
if (data.content.act.name == "unregprod") {
await postToChannel(
"@teloskickbot",
data.content.producer.toUpperCase() +
" Unregistered at block " +
data.content.block_num
);
}
} else if (data.type == "delta") {
console.log("DELTA");
}
// producers[data.content.producer].missed_blocks_per_rotation++;
// console.log(producers);
ack(); // ACK when done
};
client.connect(() => {
console.log("connected!");
});