From 1ac744141fda8dfc933b9da1ffe00832af9c9d7d Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 16 Jan 2020 18:57:46 -0500 Subject: [PATCH] HTTP Duck Command --- README.md | 4 +++- commands/search/http-duck.js | 39 ++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 commands/search/http-duck.js diff --git a/README.md b/README.md index dc33ee56..cd201aa2 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Xiao is a Discord bot coded in JavaScript with ## Commands -Total: 353 +Total: 354 ### Utility: @@ -236,6 +236,7 @@ Total: 353 * **gravatar:** Responds with the Gravatar for an email. * **http-cat:** Responds with a cat for an HTTP status code. * **http-dog:** Responds with a dog for an HTTP status code. +* **http-duck:** Responds with a duck for an HTTP status code. * **imgur:** Searches Imgur for your query. * **itunes:** Searches iTunes for your query. * **jisho:** Defines a word, but with Japanese. @@ -847,6 +848,7 @@ here. * shower-thought (Shower Thought Data) - [Random-d.uk](https://random-d.uk/) * duck ([API](https://random-d.uk/api)) + * http-duck ([API](https://random-d.uk/http)) - [random.cat](https://random.cat/) * cat (API) - [RandomFox](https://randomfox.ca/) diff --git a/commands/search/http-duck.js b/commands/search/http-duck.js new file mode 100644 index 00000000..9354ad02 --- /dev/null +++ b/commands/search/http-duck.js @@ -0,0 +1,39 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class HttpDuckCommand extends Command { + constructor(client) { + super(client, { + name: 'http-duck', + group: 'search', + memberName: 'http-duck', + description: 'Responds with a duck for an HTTP status code.', + clientPermissions: ['ATTACH_FILES'], + credit: [ + { + name: 'Random-d.uk', + url: 'https://random-d.uk/', + reason: 'API', + reasonURL: 'https://random-d.uk/http' + } + ], + args: [ + { + key: 'code', + prompt: 'What code do you want to get the duck of?', + type: 'integer' + } + ] + }); + } + + async run(msg, { code }) { + try { + const { body, headers } = await request.get(`https://random-d.uk/api/http/${code}.jpg`); + return msg.say({ files: [{ attachment: body, name: `${code}.jpg` }] }); + } catch (err) { + if (err.status === 404) return msg.say('Could not find any results.'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index decc7f4d..10854d6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "110.0.3", + "version": "110.1.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {