2
0
telebot-timer/config.js
2019-10-21 14:34:51 +02:00

191 lines
3.4 KiB
JavaScript

const fs = require('fs');
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;
return {
name : "Timer",
key : "tmr",
version : 0.1,
requirements : {
gps: false,
},
text : [
{
trigger : ["/timer"],
public : true,
desc : {0:"Lists Timer Options",
1:"Liste les options de timer",
},
requirements : (bot,event,message)=>{
return new Promise((resolve, reject)=>{
if (message.from.id != message.chat.id)
return reject(410);
return resolve(200);
});
},
action : (bot,event,message)=>{
var kb = kb_gen(bot,this.arr,bot.master.lang);
return event.reply("Select An Option", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
}
},
],
reply : [],
regex : [],
media : [],
callback : [
{
trigger : 's',
requirements : (bot,event,data)=>{
return new Promise((resolve, reject)=>{
return resolve(200);
});
},
action : (bot,event,data)=>{
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);
})
}
},
],
inline : [],
new_member : (bot,event)=>{},
weburl : [],
cron : []
}
}