This commit is contained in:
Cedric Hoelzl 2020-07-02 03:01:54 +02:00
parent 46b8fe4f27
commit 44a18ca4b6

120
config.js
View File

@ -1,6 +1,5 @@
const fs = require('fs'); const fs = require('fs');
const request = require('request'); const fetch = require('node-fetch');
const utf8 = require('utf8');
const Markup = require('telegraf/markup'); const Markup = require('telegraf/markup');
const Extra = require('telegraf/extra'); const Extra = require('telegraf/extra');
@ -10,43 +9,90 @@ const db_js = require('./db.js');
var db = new db_js("17track"); var db = new db_js("17track");
//=== TOOL FUNCTIONS //=== TOOL FUNCTIONS
const track_url = 'https://t.17track.net/restapi/track'; const track_url = 'https://t.17track.net/restapi/track';
function get_tracking(trck_ids){
let options = { var cnvrt = function(v) {
url: track_url, var str = '';
qs:{ for (var i = 0; i < v.length; i++) {
"data": [], str += v.charCodeAt(i).toString(16);
"guid":"", }
"timeZoneOffset":-120 return str;
} };
}; function acc(a, b) {
for(var id in trck_ids){ var c = 1315423911 ^ b << 16;
options.qs.data.push({num:id+"",fc:0,sc:0}); 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('')
};
async function get_tracking(trck_ids){
var data = { "data": [],"guid":"","timeZoneOffset":-120 };
for(var id of trck_ids){
data.data.push({num:id,fc:0,sc:0});
} }
return new Promise((resolve,reject)=>{ var keyid = token(JSON.stringify(data));
return request(options, function (err, response, body) {
if (err) {
return reject(err);
}
if (response.statusCode != 200 ){ const opts = {
return reject(500); method: 'POST',
} body: JSON.stringify(data),
headers: {
var resp = JSON.parse(body) 'Accept': 'application/json, text/javascript, */*; q=0.01',
if(resp.reply==undefined || resp.reply=='') 'Accept-Language': 'en-US,en;q=0.5',
return reject(500); 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
var results = []; 'X-Requested-With': 'XMLHttpRequest',
for(var rr in resp.dat){ 'Referer': 'https://t.17track.net/en',
results.push({id:rr.no, date:rr.z0.a, loc:rr.z0.c, status:rr.z0.z}); 'Cookie': 'v5_TranslateLang=en; v5_AppIconsVersion=1; Last-Event-ID='+keyid,
} 'Cache-Control': 'no-cache',
return resolve(results); },
}); // agent: new http.Agent({
// keepAlive: true
// })
};
return fetch(track_url, opts)
.then(res => res.json())
.then(res => {
var results = [];
for(var rr of resp.dat){
if(rr.track)
results.push({id:rr.no, date:rr.track.z0.a, loc:rr.track.z0.c, status:rr.track.z0.z});
else
results.push({id:rr.no, date:'?', loc:'?', status:"Unknown"});
}
return results;
}); });
// -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: en-US,en;q=0.5'
// --compressed
// -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
// -H 'Referer: https://t.17track.net/en'
} }
//=== MAIN MODULE CONFIG //=== MAIN MODULE CONFIG
@ -84,7 +130,7 @@ module.exports = function(){
if(res && res != []){ if(res && res != []){
return get_tracking(res).then(res=>{ return get_tracking(res).then(res=>{
var text = "*Tracking*\n"; var text = "*Tracking*\n";
for(var rr in res){ for(var rr of res){
text+=`_${rr.id}_ (${rr.date} - ${rr.loc})\n${rr.status}\n\n`; text+=`_${rr.id}_ (${rr.date} - ${rr.loc})\n${rr.status}\n\n`;
} }
return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"}); return event.reply( text, {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
@ -158,7 +204,7 @@ module.exports = function(){
return db.get_v(event.chat.id).then(res =>{ return db.get_v(event.chat.id).then(res =>{
if(res && res != []){ if(res && res != []){
let kb = []; let kb = [];
for(var rr in res){ for(var rr of 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")]);