mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 15:56:52 +02:00
USPS Tracking Command
This commit is contained in:
@@ -42,6 +42,7 @@ TMDB_KEY=
|
||||
TUMBLR_KEY=
|
||||
TWITTER_KEY=
|
||||
TWITTER_SECRET=
|
||||
USPS_USERID=
|
||||
WATTPAD_KEY=
|
||||
WEBSTER_KEY=
|
||||
WHATANIME_KEY=
|
||||
|
||||
@@ -59,7 +59,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
* [Storyteller](https://github.com/dragonfire535/storyteller) is a Mafia bot made for Discord's 2019 Hack Week, whose features were originally built into Xiao.
|
||||
* [Meme Poster](https://github.com/dragonfire535/meme-poster) is a meme-posting webhook, inspired by an idea that started as part of Xiao.
|
||||
|
||||
## Commands (347)
|
||||
## Commands (348)
|
||||
### Utility:
|
||||
|
||||
* **eval:** Executes JavaScript code.
|
||||
@@ -228,6 +228,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
* **tv-show:** Searches TMDB for your query, getting TV show results.
|
||||
* **twitter:** Responds with information on a Twitter user.
|
||||
* **urban:** Defines a word, but with Urban Dictionary.
|
||||
* **usps-tracking:** Gets tracking information for a package shipped via USPS.
|
||||
* **visual-novel:** Responds with information on a Visual Novel.
|
||||
* **vocadb:** Searches VocaDB for your query.
|
||||
* **wattpad:** Searches Wattpad for your query.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { USPS_USERID } = process.env;
|
||||
|
||||
module.exports = class USPSTrackingCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'usps-tracking',
|
||||
aliases: ['usps-track', 'usps'],
|
||||
group: 'search',
|
||||
memberName: 'usps-tracking',
|
||||
description: 'Gets tracking information for a package shipped via USPS.',
|
||||
credit: [
|
||||
{
|
||||
name: 'USPS',
|
||||
url: 'https://www.usps.com/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
label: 'tracking id',
|
||||
prompt: 'What is the tracking ID of the package you would like to track?',
|
||||
type: 'string',
|
||||
validate: id => /^[0-9]+$/.test(id)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id }) {
|
||||
try {
|
||||
const summary = await this.fetchSummary(id);
|
||||
if (!summary) return msg.say('A status update is not yet available on your package. Check back soon.');
|
||||
return msg.say(stripIndents`
|
||||
**Tracking info for ${id}:**
|
||||
${summary}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async fetchSummary(id) {
|
||||
const { text } = await request
|
||||
.get('https://secure.shippingapis.com/ShippingApi.dll')
|
||||
.query({
|
||||
API: 'TrackV2',
|
||||
XML: `<TrackRequest USERID="${USPS_USERID}"><TrackID ID="${id}"></TrackID></TrackRequest>`
|
||||
});
|
||||
if (text.includes('<Number>-2147219283</Number>')) return null;
|
||||
if (text.includes('<Error>')) throw new Error(text.match(/<Description>(.+)<\/Description>/i)[1].trim());
|
||||
const summary = text.match(/<TrackSummary>(.+)<\/TrackSummary>/i)[1].trim();
|
||||
return summary;
|
||||
}
|
||||
};
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "107.6.0",
|
||||
"version": "107.7.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
@@ -37,9 +37,9 @@
|
||||
"custom-translate": "^2.2.8",
|
||||
"discord.js": "github:discordjs/discord.js",
|
||||
"discord.js-commando": "github:discordjs/Commando",
|
||||
"dotenv": "^8.0.0",
|
||||
"dotenv": "^8.1.0",
|
||||
"gifencoder": "^2.0.1",
|
||||
"mathjs": "^6.0.4",
|
||||
"mathjs": "^6.1.0",
|
||||
"moment": "^2.24.0",
|
||||
"moment-duration-format": "^2.3.2",
|
||||
"moment-timezone": "^0.5.26",
|
||||
|
||||
Reference in New Issue
Block a user