130 lines
3.4 KiB
JavaScript
130 lines
3.4 KiB
JavaScript
const fs = require('fs');
|
|
|
|
const Markup = require('telegraf/markup');
|
|
const Extra = require('telegraf/extra');
|
|
|
|
const db_js = require('./db.js');
|
|
|
|
var db = new db_js("17track");
|
|
|
|
//=== TOOL FUNCTIONS
|
|
|
|
/* Here you usualy write util functions that are used multiple times in the code (or a second file is recommended)*/
|
|
|
|
//=== MAIN MODULE CONFIG
|
|
|
|
module.exports = function(){
|
|
this.key = "17trk";
|
|
return {
|
|
name : "17Track", //Unique Module name
|
|
key : this.key, //Unique Key for this module, if multiple instances add a number/text to it
|
|
version : 0.1, //Version Number, Currently unused
|
|
requirements : {
|
|
gps: false, //Currently un-used (all module have access to GPS)
|
|
},
|
|
text : [
|
|
{
|
|
trigger : ["/track"], //Array of Triggers
|
|
public : true, //Should it be shown to user (user can still run the command without knowing it exists)
|
|
desc : {0:"Tracking with options",
|
|
1:"*insert french*",
|
|
2:"*insert japanese*",
|
|
3:"*insert arabic*",
|
|
},
|
|
requirements : (bot,event,message)=>{
|
|
return new Promise((resolve, reject)=>{
|
|
return resolve(200);
|
|
});
|
|
},
|
|
action : (bot,event,message)=>{
|
|
let kb = [];
|
|
kb.push([bot.mkcb("Add","add",""),
|
|
bot.mkcb("Delete","del","")]);
|
|
kb.push([bot.mkcb_close("Close")]);
|
|
|
|
return db.get_v(event.chat.id).then(res =>{
|
|
console.log(res);
|
|
return event.reply( (res+"") , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
|
}).catch(err => {
|
|
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.replace('.','').split('\n');
|
|
return db.get_v(event.chat.id).then(res =>{
|
|
return db.set_v(event.chat.id,res.concat(ids)).then(res=>{
|
|
return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"})
|
|
});
|
|
}).catch(err => {
|
|
return db.set_v(event.chat.id, ids).then(res=>{
|
|
return event.reply("Added ids to Tracking.", {"parse_mode":"Markdown"});
|
|
});
|
|
|
|
})
|
|
}
|
|
}
|
|
],
|
|
regex : [],
|
|
media : [],
|
|
callback : [
|
|
{
|
|
trigger : 'add',
|
|
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");
|
|
}
|
|
},
|
|
{
|
|
trigger : 'del',
|
|
requirements : (bot,event,data)=>{
|
|
return new Promise((resolve, reject)=>{
|
|
return resolve(200);
|
|
});
|
|
},
|
|
action : (bot,event,data)=>{
|
|
console.log(data);
|
|
if(data){
|
|
return db.get_v(event.chat.id).then(res=>{
|
|
db.set_v(event.chat.id,res.remove(data));
|
|
});
|
|
}else{
|
|
return db.get_v(event.chat.id).then(res =>{
|
|
|
|
let kb = [];
|
|
for(var rr in 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"});
|
|
}).catch(err => {
|
|
return event.reply("*No Tracking To Delete*", {"parse_mode":"Markdown"})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
],
|
|
inline : [],
|
|
new_member : (bot,event)=>{},
|
|
weburl : [],
|
|
cron : []
|
|
}
|
|
|
|
} |