const fs = require('fs'); const Markup = require('telegraf/markup'); const Extra = require('telegraf/extra'); const request = require('request'); const db_json = require('./jsondb.js'); const url = 'https://polylan.ch'; const groupid = -14795224; const regex_pre = /([0-9]*)/ const regex_ins = /([0-9]*)/ function get_count(){ return new Promise((resolve,reject)=>{ request(url, function (error, response, body) { try{ let d1 = parseInt(body.match(regex_pre)[1]); let d2 = parseInt(body.match(regex_ins)[1]); resolve([d1,d2]); }catch(e){ reject(e); } }); }) } //=== MAIN MODULE CONFIG module.exports = function(name){ this.db = db_json(name); return { name : "PolyCB", key : "pycb", version : 0.1, requirements : { gps: false, }, text : [ { trigger : ["/combien"], public : true, desc : {0:"Shows how many people registered to polylan", 1:"Affiche combien de personnes se sont enregistré pour le PolyLAN", }, requirements : (bot,event,message)=>{ return new Promise((resolve, reject)=>{ return resolve(200); }); }, action : (bot,event,message)=>{ return get_count().then(res=>{ return event.replyWithMarkdown("*"+res[0]+"* pré-inscrits\n*"+res[1]+"* inscrits"); }).catch(err=>{ return bot.error(err); }); } }, ], reply : [], regex : [], media : [], callback : [], inline : [], new_member : (bot,event)=>{}, weburl : [], cron : [ { cstr : '59 34 0,6,12,18 * * *', public : true, desc : { 0: "Tries to reply to the PolyCombien Values At right time", }, params : [ null, true], timezone : 'Europe/Zurich', action : function(bot){ this.bot = bot; return ()=>{ return this.bot.telegram.sendMessage(groupid,"Mieux que 0 !",{}); } } } ] } }