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

101
config.js
View File

@ -122,69 +122,64 @@ module.exports = function(){
},
action : (bot,event,message)=>{
let kb = [];
kb.push([bot.mkcb("Add","add",""),
bot.mkcb("Delete","del","")]);
kb.push([bot.mkcb_close("Close")]);
kb.push([bot.mkcb("Refresh","refresh","")]) ;
kb.push([bot.mkcb_close("Close"),bot.mkcb("Delete","del","")]);
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 =>{
if(res && res != []){
var ids = res.concat(new_ids);
if(ids.length == 0){
return event.reply("*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*\n\n";
for(var rr of res){
text+=`*${rr.id}* (_${rr.date} - ${rr.loc}_)\n${rr.status}\n\n`;
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"});
});
}else{
return event.reply("*No Tracking Yet*", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
});
}
})
});
}
},
],
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"});
});
}
})
}
}
],
reply : [],
regex : [],
media : [],
callback : [
{
trigger : 'add',
trigger : 'refresh',
requirements : (bot,event,data)=>{
return new Promise((resolve, reject)=>{
return resolve(200);
});
},
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,29 +190,31 @@ module.exports = function(){
});
},
action : (bot,event,data)=>{
if(data){
return db.get_v(event.chat.id).then(res=>{
for( var i = 0; i < res.length; i++){
if ( res[i] == data) {
res.splice(i, 1); }}
db.set_v(event.chat.id,res);
});
}else{
return db.get_v(event.chat.id).then(res =>{
if(res && res != []){
if(data){
for( var i = 0; i < res.length; i++){
if ( res[i] == data) {
res.splice(i, 1);
}
}
return db.set_v(event.chat.id,res).then(res=>{
return event.editMessageText("*Tracking Deleted*", {"parse_mode":"Markdown"});
});
}else{
let kb = [];
for(var rr of res){
kb.push([bot.mkcb(rr,"del",rr)])
}
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"})
return event.editMessageText("*No Tracking To Delete*", {"parse_mode":"Markdown"});
}
});
}
}
}
],
inline : [],
new_member : (bot,event)=>{},