fix
This commit is contained in:
parent
214ccc3986
commit
ed62a59117
119
config.js
119
config.js
@ -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 != []){
|
||||
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`;
|
||||
}
|
||||
return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
||||
});
|
||||
var ids = res.concat(new_ids);
|
||||
if(ids.length == 0){
|
||||
return event.reply("*No Tracking Yet*", {"parse_mode":"Markdown"});
|
||||
}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 : [
|
||||
{
|
||||
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,27 +190,29 @@ 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 != []){
|
||||
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"});
|
||||
}else{
|
||||
return event.reply("*No Tracking To Delete*", {"parse_mode":"Markdown"})
|
||||
return event.editMessageText( "Select Tracking Number To Delete" , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
return event.editMessageText("*No Tracking To Delete*", {"parse_mode":"Markdown"});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user