kk
This commit is contained in:
parent
a36b90c104
commit
46b8fe4f27
48
config.js
48
config.js
@ -1,4 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const request = require('request');
|
||||
const utf8 = require('utf8');
|
||||
|
||||
const Markup = require('telegraf/markup');
|
||||
const Extra = require('telegraf/extra');
|
||||
@ -8,8 +10,44 @@ const db_js = require('./db.js');
|
||||
var db = new db_js("17track");
|
||||
|
||||
//=== TOOL FUNCTIONS
|
||||
const track_url = 'https://t.17track.net/restapi/track';
|
||||
function get_tracking(trck_ids){
|
||||
let options = {
|
||||
url: track_url,
|
||||
qs:{
|
||||
"data": [],
|
||||
"guid":"",
|
||||
"timeZoneOffset":-120
|
||||
}
|
||||
};
|
||||
for(var id in trck_ids){
|
||||
options.qs.data.push({num:id+"",fc:0,sc:0});
|
||||
}
|
||||
return new Promise((resolve,reject)=>{
|
||||
return request(options, function (err, response, body) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
/* Here you usualy write util functions that are used multiple times in the code (or a second file is recommended)*/
|
||||
if (response.statusCode != 200 ){
|
||||
return reject(500);
|
||||
}
|
||||
|
||||
var resp = JSON.parse(body)
|
||||
if(resp.reply==undefined || resp.reply=='')
|
||||
return reject(500);
|
||||
var results = [];
|
||||
for(var rr in resp.dat){
|
||||
results.push({id:rr.no, date:rr.z0.a, loc:rr.z0.c, status:rr.z0.z});
|
||||
}
|
||||
return resolve(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
|
||||
|
||||
@ -44,7 +82,13 @@ module.exports = function(){
|
||||
|
||||
return db.get_v(event.chat.id).then(res =>{
|
||||
if(res && res != []){
|
||||
return event.reply( res , {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
||||
return get_tracking(res).then(res=>{
|
||||
var text = "*Tracking*\n";
|
||||
for(var rr in 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"});
|
||||
});
|
||||
}else{
|
||||
return event.reply("*No Tracking Yet*", {"reply_markup":Markup.inlineKeyboard(kb),"parse_mode":"Markdown"});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user