This commit is contained in:
Cedric Hoelzl 2020-07-01 11:32:09 +02:00
parent 2750d2a520
commit fd131b0b1d
2 changed files with 9 additions and 10 deletions

View File

@ -60,18 +60,16 @@ module.exports = function(){
{ {
requirements : (bot,event,message)=>{ requirements : (bot,event,message)=>{
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
if(!message.text || message.reply_to_message.text != "Reply to this message with a tracking id") if(!message.text || message.reply_to_message.text != "Reply to this message with a tracking id.")
return reject(400); return reject(400);
return resolve(200); return resolve(200);
}); });
}, },
action : (bot,event,message)=>{ action : (bot,event,message)=>{
var ids = message.text.replace('.','').split('\n'); var ids = message.text.replace('.','').replace(',','').split('\n');
console.log(ids);
return db.get_v(event.chat.id).then(res =>{ return db.get_v(event.chat.id).then(res =>{
if(res){ if(res){
return db.set_v(event.chat.id,res.concat(ids)).then(res=>{ return db.set_v(event.chat.id,res.concat(ids)).then(res=>{
console.log(res)
return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"}) return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"})
}); });
}else{ }else{
@ -96,7 +94,7 @@ module.exports = function(){
}); });
}, },
action : (bot,event,data)=>{ action : (bot,event,data)=>{
return event.reply("Reply to this message with a tracking id"); return event.reply("Reply to this message with a tracking id.");
} }
}, },
{ {
@ -115,15 +113,16 @@ module.exports = function(){
}else{ }else{
return db.get_v(event.chat.id).then(res =>{ return db.get_v(event.chat.id).then(res =>{
if(res){
let kb = []; let kb = [];
for(var rr in res){ for(var rr in 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.reply( (res+"") , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
}).catch(err => { }else{
return event.reply("*No Tracking To Delete*", {"parse_mode":"Markdown"}) return event.reply("*No Tracking To Delete*", {"parse_mode":"Markdown"})
}) }
} }
} }
} }

4
db.js
View File

@ -42,13 +42,13 @@ module.exports = function(name){
this.set_v = function(cid,v){ this.set_v = function(cid,v){
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
resolve(this.db.find({id:cid}).set('tracking',v).write()); resolve(this.db.get("chats").find({id:cid}).set('tracking',v).write());
}); });
}; };
this.get_v = function(cid){ this.get_v = function(cid){
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
resolve(this.db.find({id:cid}).value()); resolve(this.db.get("chats").find({id:cid}).value());
}); });
} }