This commit is contained in:
Cedric Hoelzl 2020-07-02 09:17:34 +02:00
parent 214ccc3986
commit ed62a59117

119
config.js
View File

@ -122,69 +122,64 @@ module.exports = function(){
}, },
action : (bot,event,message)=>{ action : (bot,event,message)=>{
let kb = []; let kb = [];
kb.push([bot.mkcb("Add","add",""), kb.push([bot.mkcb("Refresh","refresh","")]) ;
bot.mkcb("Delete","del","")]); kb.push([bot.mkcb_close("Close"),bot.mkcb("Delete","del","")]);
kb.push([bot.mkcb_close("Close")]); var new_ids = [];
if(message.text_arg && message.text_arg.length >0){
new_ids = message.text_args.replace('.','').replace(',','\n').replace(' ','\n').split('\n');
}
return db.get_v(event.chat.id).then(res =>{ return db.get_v(event.chat.id).then(res =>{
if(res && res != []){ var ids = res.concat(new_ids);
return get_tracking(res).then(res=>{ if(ids.length == 0){
var text = "*Tracking*\n\n"; return event.reply("*No Tracking Yet*", {"parse_mode":"Markdown"});
for(var rr of res){
text+=`*${rr.id}* (_${rr.date} - ${rr.loc}_)\n${rr.status}\n\n`;
}
return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
});
}else{ }else{
return event.reply("*No Tracking Yet*", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"}); return db.set_v(event.chat.id,ids).then(res=>{
return get_tracking(res).then(res=>{
var text = "*Tracking*\n\n";
for(var rr of res){
text+=`*${rr.id}* (_${rr.date?rr.date:'Unknown'} - ${rr.loc?rr.loc:'Unknown'}_)\n${rr.status}\n\n`;
}
return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
});
});
} }
}) });
} }
}, },
], ],
reply : [ reply : [],
{
requirements : (bot,event,message)=>{
return new Promise((resolve,reject)=>{
if(!message.text || message.reply_to_message.text != "Reply to this message with a tracking id.")
return reject(400);
return resolve(200);
});
},
action : (bot,event,message)=>{
var ids = message.text.replace('.','').replace(',','').split('\n');
return db.get_v(event.chat.id).then(res =>{
if(res && res != []){
return db.set_v(event.chat.id,res.concat(ids)).then(res=>{
return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"})
});
}else{
return db.set_v(event.chat.id, ids).then(res=>{
console.log(res)
return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"});
});
}
})
}
}
],
regex : [], regex : [],
media : [], media : [],
callback : [ callback : [
{ {
trigger : 'add', trigger : 'refresh',
requirements : (bot,event,data)=>{ requirements : (bot,event,data)=>{
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
return resolve(200); return resolve(200);
}); });
}, },
action : (bot,event,data)=>{ action : (bot,event,data)=>{
return event.reply("Reply to this message with a tracking id."); let kb = [];
kb.push([bot.mkcb("Refresh","refresh","")]) ;
kb.push([bot.mkcb_close("Close"),bot.mkcb("Delete","del","")]);
return db.get_v(event.chat.id).then(res =>{
var ids = res;
if(ids.length == 0){
return event.editMessageText("*No Tracking Yet*", {"parse_mode":"Markdown"});
}else{
return db.set_v(event.chat.id,ids).then(res=>{
return get_tracking(res).then(res=>{
var text = `*Tracking* (Updated: ${new Date().toLocaleString()})\n\n`;
for(var rr of res){
text+=`*${rr.id}* (_${rr.date?rr.date:'Unknown'} - ${rr.loc?rr.loc:'Unknown'}_)\n${rr.status}\n\n`;
}
return event.editMessageText( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
});
});
}
});
} }
}, },
{ {
@ -195,27 +190,29 @@ module.exports = function(){
}); });
}, },
action : (bot,event,data)=>{ action : (bot,event,data)=>{
if(data){ return db.get_v(event.chat.id).then(res =>{
return db.get_v(event.chat.id).then(res=>{ if(res && res != []){
for( var i = 0; i < res.length; i++){ if(data){
if ( res[i] == data) { for( var i = 0; i < res.length; i++){
res.splice(i, 1); }} if ( res[i] == data) {
db.set_v(event.chat.id,res); res.splice(i, 1);
}); }
}else{ }
return db.get_v(event.chat.id).then(res =>{ return db.set_v(event.chat.id,res).then(res=>{
if(res && res != []){ return event.editMessageText("*Tracking Deleted*", {"parse_mode":"Markdown"});
});
}else{
let kb = []; let kb = [];
for(var rr of res){ for(var rr of res){
kb.push([bot.mkcb(rr,"del",rr)]) kb.push([bot.mkcb(rr,"del",rr)])
} }
kb.push([bot.mkcb_close("Close")]); kb.push([bot.mkcb_close("Close")]);
return event.reply( (res+"") , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"}); return event.editMessageText( "Select Tracking Number To Delete" , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
}else{
return event.reply("*No Tracking To Delete*", {"parse_mode":"Markdown"})
} }
}); }else{
} return event.editMessageText("*No Tracking To Delete*", {"parse_mode":"Markdown"});
}
});
} }
} }
], ],