61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
|
|
const request = require('request');
|
|
const parse5 = require('parse5');
|
|
|
|
const url = 'https://polylan.ch';
|
|
const groupid = -14795224;
|
|
|
|
let old1 = 1179
|
|
let old2 = 486
|
|
function cb(ret,err){
|
|
request(url, function (error, response, body) {
|
|
try{
|
|
const doc = parse5.parse(body).childNodes[1].childNodes[2].childNodes[34].childNodes[1].childNodes[1].childNodes[1].childNodes[5];
|
|
const d1 = doc.childNodes[1].childNodes[3].childNodes[3].childNodes[4].value;
|
|
const d2 = doc.childNodes[3].childNodes[3].childNodes[3].childNodes[4].value;
|
|
|
|
const dif1 = d1 - old1;
|
|
const dif2 = d2 - old2;
|
|
old1 = d1
|
|
old2 = d2
|
|
|
|
ret([dif2,dif1]);
|
|
}catch(e){
|
|
err( e);
|
|
}
|
|
});
|
|
}
|
|
|
|
function handle_message (event, bot){
|
|
if(event.update.message.text){
|
|
var txt = event.update.message.text;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = function(){
|
|
|
|
this.cron = function(cron,bot){
|
|
this.bot = bot;
|
|
this.cronb = function(that){
|
|
new cron('59 34 0,6,12,18 * * *', function(){
|
|
cb((res)=>{
|
|
return that.bot.telegram.sendMessage(groupid,"Mieux que 0 !",{});
|
|
},(err)=>{
|
|
bot.log.error(err)
|
|
return;
|
|
})
|
|
}, null, true, 'Europe/Zurich');
|
|
}
|
|
}
|
|
this.handle = function(event, bot){
|
|
if(event.update.message){
|
|
return handle_message(event, bot);
|
|
}
|
|
return;
|
|
}
|
|
|
|
this.name = "PolyCB";
|
|
}
|