2020-07-01 11:00:51 +02:00
|
|
|
const fs = require('fs');
|
2020-07-02 03:01:54 +02:00
|
|
|
const fetch = require('node-fetch');
|
2020-07-01 11:00:51 +02:00
|
|
|
|
|
|
|
const Markup = require('telegraf/markup');
|
|
|
|
const Extra = require('telegraf/extra');
|
|
|
|
|
|
|
|
const db_js = require('./db.js');
|
2020-07-02 14:11:52 +02:00
|
|
|
const tracking = require('./tracking.js');
|
2020-07-01 11:00:51 +02:00
|
|
|
|
|
|
|
var db = new db_js("17track");
|
|
|
|
|
|
|
|
//=== TOOL FUNCTIONS
|
2020-07-02 03:01:54 +02:00
|
|
|
|
|
|
|
|
2020-07-01 12:03:06 +02:00
|
|
|
const track_url = 'https://t.17track.net/restapi/track';
|
2020-07-01 11:00:51 +02:00
|
|
|
|
2020-07-02 03:01:54 +02:00
|
|
|
var cnvrt = function(v) {
|
|
|
|
var str = '';
|
|
|
|
for (var i = 0; i < v.length; i++) {
|
|
|
|
str += v.charCodeAt(i).toString(16);
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
};
|
|
|
|
function acc(a, b) {
|
|
|
|
var c = 1315423911 ^ b << 16;
|
|
|
|
for (var i = a.length - 1; i >= 0; i--) {
|
|
|
|
c ^= (c << 5) + a.charCodeAt(i) + (c >> 2);
|
|
|
|
}
|
|
|
|
return Math.abs(c & 2147483647);
|
|
|
|
};
|
|
|
|
function atb(a) {
|
|
|
|
var b = a;
|
|
|
|
while (b['length'] < 0x8) {
|
|
|
|
b = '0' + b;
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
};
|
|
|
|
var token = function(data) {
|
|
|
|
var classes = ["navbar navbar-default yq-header", "nav navbar-toolbar navbar-right navbar-toolbar-right yq-navbar-toolbar", "yq-dropdown-menu-media-apps", "yq-navbar-menuIcon-24 yq-head-apps", "dropdown-menu yq-moreapp-container", "list-group yq-list-group-moreapp clearfix", "hide yq-dropdown-menu-media-msg", "yq-head-msg yq-navbar-menuIcon-24", "yq-msg-nomsg vertical-align panel text-center hide", "yq-msg-network-err vertical-align panel text-center hide", "dropdown-menu dropdown-menu-media yq-dropdown-menu-media-user", "dropdown-menu-footer yq-user-footer clearfix", "margin-horizontal-10 yq-input-container", "dropdown-menu dropdown-menu-media yq-track-dropdown", "yq-more-track-container clearfix", "yq-tools-small", "navbar-brand-logo hidden-xs yq-default-logo", "navbar-brand-logo visible-xs yq-default-logo", "tab-content yq-panel-tracklist scrollable is-enabled scrollable-vertical", "yq-panel-gad", "modal-dialog yq-modal-dialog"];
|
|
|
|
var rnd = Math.round((Math.random()* classes.length));
|
|
|
|
|
|
|
|
var res = [];
|
|
|
|
var value = "yq-";
|
|
|
|
var key = "Last-Event-ID";
|
|
|
|
if (classes.length > rnd) {
|
|
|
|
value = classes[rnd];
|
|
|
|
}
|
|
|
|
value += '/' + Date.now().toString(16) + '/18c/true';
|
|
|
|
|
|
|
|
res[0]= cnvrt(value.split('').reverse().join(''));
|
|
|
|
res[1] = rnd.toString(16);
|
|
|
|
res[2] = rnd.toString(16).length;
|
|
|
|
res[3] = 2;
|
|
|
|
res[4] = atb(acc(value, rnd).toString(16));
|
|
|
|
res[5] = atb(acc(data,data.length).toString(16));
|
|
|
|
return res.join('')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-02 14:34:29 +02:00
|
|
|
const get_tracking = async function(trck_ids){
|
2020-07-02 03:01:54 +02:00
|
|
|
|
|
|
|
var data = { "data": [],"guid":"","timeZoneOffset":-120 };
|
|
|
|
for(var id of trck_ids){
|
|
|
|
data.data.push({num:id,fc:0,sc:0});
|
|
|
|
}
|
|
|
|
var keyid = token(JSON.stringify(data));
|
|
|
|
|
|
|
|
const opts = {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
|
|
'Accept-Language': 'en-US,en;q=0.5',
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
'Referer': 'https://t.17track.net/en',
|
|
|
|
'Cookie': 'v5_TranslateLang=en; v5_AppIconsVersion=1; Last-Event-ID='+keyid,
|
|
|
|
'Cache-Control': 'no-cache',
|
|
|
|
},
|
|
|
|
// agent: new http.Agent({
|
|
|
|
// keepAlive: true
|
|
|
|
// })
|
|
|
|
};
|
|
|
|
return fetch(track_url, opts)
|
|
|
|
.then(res => res.json())
|
|
|
|
.then(res => {
|
|
|
|
var results = [];
|
2020-07-02 03:03:06 +02:00
|
|
|
for(var rr of res.dat){
|
2020-07-02 03:01:54 +02:00
|
|
|
if(rr.track)
|
2020-07-02 14:33:34 +02:00
|
|
|
results.push({id:rr.no, date:rr.track.z0.a, loc:rr.track.z0.c, status:rr.track.z0.z, e: rr.track.e});
|
2020-07-02 03:01:54 +02:00
|
|
|
else
|
2020-07-02 14:33:34 +02:00
|
|
|
results.push({id:rr.no, date:'', loc:'', status:"Unknown", e:0});
|
2020-07-02 03:01:54 +02:00
|
|
|
}
|
|
|
|
return results;
|
2020-07-01 12:03:06 +02:00
|
|
|
});
|
|
|
|
}
|
2020-07-01 11:00:51 +02:00
|
|
|
|
2020-07-02 14:33:34 +02:00
|
|
|
|
|
|
|
const tracking_status = function(e){
|
|
|
|
switch(e/10){
|
|
|
|
case 0: return "Not Found";
|
|
|
|
case 1: return "In Transit";
|
|
|
|
case 2: return "Expired";
|
|
|
|
case 3:
|
|
|
|
if(e == 35){
|
|
|
|
return "Undelivered";
|
|
|
|
}else{
|
|
|
|
return "Pick Up";
|
|
|
|
}
|
|
|
|
case 4: return "Delivered";
|
|
|
|
case 5: return "Warning";
|
|
|
|
case 6: return "";
|
|
|
|
default: return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 11:00:51 +02:00
|
|
|
//=== 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 = [];
|
2020-07-02 09:17:34 +02:00
|
|
|
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){
|
2020-07-14 13:40:26 +02:00
|
|
|
new_ids = message.text_arg.replace('.','').replace(',','\n').replace(' ','\n').split('\n');
|
2020-07-02 09:17:34 +02:00
|
|
|
}
|
2020-07-01 11:00:51 +02:00
|
|
|
return db.get_v(event.chat.id).then(res =>{
|
2020-07-02 09:17:34 +02:00
|
|
|
var ids = res.concat(new_ids);
|
|
|
|
if(ids.length == 0){
|
|
|
|
return event.reply("*No Tracking Yet*", {"parse_mode":"Markdown"});
|
2020-07-01 11:15:24 +02:00
|
|
|
}else{
|
2020-07-02 09:17:34 +02:00
|
|
|
return db.set_v(event.chat.id,ids).then(res=>{
|
2020-07-02 09:23:09 +02:00
|
|
|
return get_tracking(ids).then(res=>{
|
2020-07-02 09:17:34 +02:00
|
|
|
var text = "*Tracking*\n\n";
|
|
|
|
for(var rr of res){
|
2020-07-02 14:33:34 +02:00
|
|
|
text+=`[${rr.id}](${tracking.getTrackingUrl(rr.id)}) - _${tracking_status(rr.e)}_\n_${rr.date?rr.date:'Unknown'} - ${rr.loc?rr.loc:'Unknown'}_\n${rr.status}\n\n`;
|
2020-07-02 09:17:34 +02:00
|
|
|
}
|
|
|
|
return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
|
|
|
});
|
2020-07-01 11:15:24 +02:00
|
|
|
});
|
|
|
|
}
|
2020-07-01 11:00:51 +02:00
|
|
|
|
2020-07-02 09:17:34 +02:00
|
|
|
});
|
2020-07-01 11:00:51 +02:00
|
|
|
}
|
2020-07-02 09:17:34 +02:00
|
|
|
},
|
2020-07-01 11:00:51 +02:00
|
|
|
],
|
2020-07-02 09:17:34 +02:00
|
|
|
reply : [],
|
2020-07-01 11:00:51 +02:00
|
|
|
regex : [],
|
|
|
|
media : [],
|
|
|
|
callback : [
|
|
|
|
{
|
2020-07-02 09:17:34 +02:00
|
|
|
trigger : 'refresh',
|
2020-07-01 11:00:51 +02:00
|
|
|
requirements : (bot,event,data)=>{
|
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
|
return resolve(200);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
action : (bot,event,data)=>{
|
2020-07-02 09:17:34 +02:00
|
|
|
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 =>{
|
2020-07-02 09:23:09 +02:00
|
|
|
if(res.length == 0){
|
2020-07-02 09:17:34 +02:00
|
|
|
return event.editMessageText("*No Tracking Yet*", {"parse_mode":"Markdown"});
|
|
|
|
}else{
|
2020-07-02 09:28:08 +02:00
|
|
|
return db.set_v(event.chat.id,res).then(sres=>{
|
2020-07-02 09:17:34 +02:00
|
|
|
return get_tracking(res).then(res=>{
|
|
|
|
var text = `*Tracking* (Updated: ${new Date().toLocaleString()})\n\n`;
|
|
|
|
for(var rr of res){
|
2020-07-02 14:33:34 +02:00
|
|
|
text+=`[${rr.id}](${tracking.getTrackingUrl(rr.id)}) - _${tracking_status(rr.e)}_\n_${rr.date?rr.date:'Unknown'} - ${rr.loc?rr.loc:'Unknown'}_\n${rr.status}\n\n`;
|
2020-07-02 09:17:34 +02:00
|
|
|
}
|
|
|
|
return event.editMessageText( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2020-07-01 11:00:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
trigger : 'del',
|
|
|
|
requirements : (bot,event,data)=>{
|
|
|
|
return new Promise((resolve, reject)=>{
|
|
|
|
return resolve(200);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
action : (bot,event,data)=>{
|
2020-07-02 09:17:34 +02:00
|
|
|
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{
|
2020-07-01 11:33:32 +02:00
|
|
|
let kb = [];
|
2020-07-02 03:01:54 +02:00
|
|
|
for(var rr of res){
|
2020-07-01 11:33:32 +02:00
|
|
|
kb.push([bot.mkcb(rr,"del",rr)])
|
|
|
|
}
|
|
|
|
kb.push([bot.mkcb_close("Close")]);
|
2020-07-02 09:17:34 +02:00
|
|
|
return event.editMessageText( "Select Tracking Number To Delete" , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
2020-07-01 11:00:51 +02:00
|
|
|
}
|
2020-07-02 09:17:34 +02:00
|
|
|
}else{
|
|
|
|
return event.editMessageText("*No Tracking To Delete*", {"parse_mode":"Markdown"});
|
|
|
|
}
|
|
|
|
});
|
2020-07-01 11:00:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
inline : [],
|
|
|
|
new_member : (bot,event)=>{},
|
|
|
|
weburl : [],
|
|
|
|
cron : []
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|