-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebhook.js
50 lines (41 loc) · 1.29 KB
/
webhook.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
const debug = require('debug')('parking.sinpapeles:ws');
const { client, getParking } = require('./services/hsd');
const { ChainEntry } = require('hsd');
const {
isLink,
isPrice,
isAuth,
saveName,
saveAuth,
getNewNames,
getPunycode,
sendTelegram,
processAndSendTwitter,
} = require('./utils');
module.exports = async () => {
await client.open();
return () => client.close();
};
client.bind('chain connect', async raw => {
const { height } = ChainEntry.fromRaw(raw);
debug(`New block: ${height}`);
onNewBlock(height);
});
// onNewBlock(62579);
const onNewBlock = async height => {
const data = await getParking(height);
data.map(({ name, txt }) => {
const contact = isLink(txt.parking) ? txt.parking : null;
const value = isPrice(txt.parkingValue) ? txt.parkingValue : '';
const auth = isAuth(txt.auth) ? txt.auth : '';
saveName(name, contact, value, height);
saveAuth(name, auth);
});
const parking = getNewNames(height);
console.log(parking);
if (parking.length) {
sendTelegram(`*Parking Sinpapeles:* ${parking.length} new domain\\(s\\):
${parking.map(p => getPunycode(p.name).replace(/-/g, '\\-').replace(/_/g, '\\_')).join('\n')}`);
processAndSendTwitter(parking);
}
};