From d47abc53379e0971eb363317feee167efaf54bfb Mon Sep 17 00:00:00 2001 From: Cedric Hoelzl Date: Mon, 21 Oct 2019 14:34:51 +0200 Subject: [PATCH] coded --- config.js | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 5 deletions(-) diff --git a/config.js b/config.js index 0712f33..874aca1 100644 --- a/config.js +++ b/config.js @@ -4,8 +4,118 @@ const Markup = require('telegraf/markup'); const Extra = require('telegraf/extra'); //=== MAIN MODULE CONFIG +async function wait(min) { + return new Promise(resolve => { + setTimeout(resolve, min*60000); + }); +} + + +const tmr = { + atrium:{ + desc:{ + 0:"Atrium Laundry", + 1:"Lessive Atrium" + }, + sub:{ + wash:{ + desc:{ + 0:"Washing Machine", + 1:"Lave Linge" + }, + tmr: [45,45,45], + tmr_str: ["A","B","C"], + }, + dry:{ + desc:{ + 0:"Dryer", + 1:"Sèche Linge" + }, + tmr: [45,45,45,45], + tmr_str: ["+++","++","+","-"] + } + } + }, + basic:{ + desc:{ + 0:"Basic Timers", + 1:"Timer Basique", + }, + sub:{ + min:{ + desc:{ + 0:"Minutes", + 1:"Minutes" + }, + tmr: [5,10,15,30,45], + tmr_str: [5,10,15,30,45], + }, + hour:{ + desc:{ + 0:"Hours", + 1:"Heures" + }, + tmr: [1*60,2*60,4*60,6*60,12*60], + tmr_str: [1,2,4,6,12], + } + } + } +} + +const cbt = { + run:"r", + sel:"s", +} + +function gen_kb(bot, parr,lang){ + let bck_nxt = ""; + let bck = ""; + let kb = []; + let ntmr = tmr; + for(let pp of parr){ + try{ + if(ntmr[pp].sub){ + bck = bck_nxt; + bck_nxt = pp.toString(); + ntmr = ntmr[pp].sub; + }else{ + bck = bck_nxt; + ntmr = ntmr[pp]; + } + }catch(err){ + return []; + } + } + if(ntmr){ + for(let k of Object.keys(ntmr)){ + let ctmr = ntmr[k]; + if(ctmr.sub){ + let str = ctmr.desc[lang]; + kb.push(bot.mkcb(str,cbt.sel,k)); + }else if(ctmr.tmr){ + let str = ctmr.desc[lang]; + let c = arr.join("_") + "_" + k.toString(); + + kb.push(bot.mkcb(str,cbt.sel,c)); + } + } + if(ntmr.tmr){ + for(let i in ntmr.tmr){ + let v = ntmr.tmr[i]; + let str = ntmr.tmr_str[i]; + kb.push(bot.mkcb(str,cbt.run,v)) + } + } + } + + kb.push(bot.mkcb("Back",cbt.sel,bck)); + return kb; +} + + +module.exports = function(arr){ + this.arr = arr; -module.exports = function(){ return { name : "Timer", key : "tmr", @@ -28,7 +138,9 @@ module.exports = function(){ }); }, action : (bot,event,message)=>{ - return event.reply("pong"); + var kb = kb_gen(bot,this.arr,bot.master.lang); + + return event.reply("Select An Option", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"}); } }, ], @@ -37,14 +149,36 @@ module.exports = function(){ media : [], callback : [ { - trigger : '...', - requirements : (bot,event,message)=>{ + trigger : 's', + requirements : (bot,event,data)=>{ return new Promise((resolve, reject)=>{ return resolve(200); }); }, action : (bot,event,data)=>{ - return event.reply("Beep"); + let arr = this.arr; + + if(data != "") arr = data.split("_"); + + let kb = kb_gen(bot,arr,bot.master.lang); + + return event.editMessageText("Select An Option", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"}); + } + }, + { + trigger : 'r', + requirements : (bot,event,data)=>{ + return new Promise((resolve, reject)=>{ + return resolve(200); + }); + }, + action : (bot,event,data)=>{ + return event.editMessageText("Running timer of "+data+" minutes !", {"parse_mode":"Markdown"}); + wait(parseInt(data)).then((res)=>{ + return event.reply("Times Up !"); + }).catch(err=>{ + bot.error(err); + }) } }, ],