adde polycb
This commit is contained in:
parent
4023d83475
commit
f8ee9fa195
91
config.js
Normal file
91
config.js
Normal file
@ -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 = /<!--STARTOFPREINS-->([0-9]*)<!--ENDOFPREINS-->/
|
||||
const regex_ins = /<!--STARTOFINS-->([0-9]*)<!--ENDOFINS-->/
|
||||
|
||||
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 !",{});
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
30
jsondb.js
Normal file
30
jsondb.js
Normal file
@ -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();
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user