From f8ee9fa195048d26101e8875fea98f56295a721b Mon Sep 17 00:00:00 2001 From: sora Date: Wed, 23 Oct 2019 11:07:22 +0200 Subject: [PATCH] adde polycb --- config.js | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ jsondb.js | 30 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 config.js create mode 100644 jsondb.js diff --git a/config.js b/config.js new file mode 100644 index 0000000..89803b2 --- /dev/null +++ b/config.js @@ -0,0 +1,91 @@ +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); + } + }); + }) + +} + +get_count().then(res=>console.log(res)) + +//=== 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]}* preinscrits\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 !",{}); + } + } + } + ] + } + +} \ No newline at end of file diff --git a/jsondb.js b/jsondb.js new file mode 100644 index 0000000..68fa8d8 --- /dev/null +++ b/jsondb.js @@ -0,0 +1,30 @@ +const fs = require('fs'); + +let db = { + pre: 0, + ins: 0, +}; + +module.exports = function(name){ + this.file = name+".json"; + this.json = db; + this.get = function(){ + + return this.json; + }; + this.set = function(njson){ + this.json = njson; + fs.writeFile(this.file, JSON.stringify(this.json,null,2), (err) => { + if (err) throw err; + }); + } + + this.init = function(){ + fs.readFile(this.file, (err, data) => { + if (err) throw err; + this.json = JSON.parse(data); + }); + } + this.init(); + +} \ No newline at end of file