From fc18e7b979db7c7b0847c417476b0da2bb75009a Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 26 Mar 2020 21:29:55 -0400 Subject: [PATCH] ISS, People in Space, and Adorable Commands --- README.md | 10 ++++++- commands/events/iss.js | 32 +++++++++++++++++++++ commands/events/people-in-space.js | 45 ++++++++++++++++++++++++++++++ commands/image-edit/adorable.js | 39 ++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 commands/events/iss.js create mode 100644 commands/events/people-in-space.js create mode 100644 commands/image-edit/adorable.js diff --git a/README.md b/README.md index d4059396..c67204ab 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ don't grant that permission. ## Commands -Total: 377 +Total: 380 ### Utility: @@ -260,7 +260,9 @@ Total: 377 * **horoscope:** Responds with today's horoscope for a specific Zodiac sign. * **humble-bundle:** Responds with the current Humble Bundle. * **is-tuesday:** Determines if today is Tuesday. +* **iss:** Responds with where the Internation Space Station currently is. * **neko-atsume-password:** Responds with today's Neko Atsume password. +* **people-in-space:** Responds with the people currently in space. * **time:** Responds with the current time in a particular location. * **today-in-history:** Responds with an event that occurred today in history. @@ -384,6 +386,7 @@ Total: 377 ### Image Manipulation: * **achievement:** Sends a Minecraft achievement with the text of your choice. +* **adorable:** Creates an adorable avatar based on the text you provide. * **apple-engraving:** Engraves the text of your choice onto an Apple product. * **approved:** Draws an "approved" stamp over an image or a user's avatar. * **axis-cult-sign-up:** Sends an Axis Cult Sign-Up sheet for you. Join today! @@ -582,6 +585,8 @@ here. * sora-selfie ([Image](https://twitter.com/Candasaurus/status/1041946636656599045)) - [@liltusk](https://twitter.com/liltusk) * food-broke ([Image](https://twitter.com/liltusk/status/835719948597137408)) +- [Adorable Avatars](http://avatars.adorable.io/) + * adorable (API) - [Advice Slip](https://adviceslip.com/) * advice ([API](https://api.adviceslip.com/)) - [Alpha Vantage](https://www.alphavantage.co/) @@ -894,6 +899,9 @@ here. * npm (API) - [Numbers API](http://numbersapi.com/) * number-fact (Trivia API) +- [Open Notify](http://open-notify.org/) + * iss ([ISS Current Location API](http://open-notify.org/Open-Notify-API/ISS-Location-Now/)) + * people-in-space ([People in Space API](http://open-notify.org/Open-Notify-API/People-In-Space/)) - [Open Trivia DB](https://opentdb.com/) * quiz ([API](https://opentdb.com/api_config.php)) * quiz-duel ([API](https://opentdb.com/api_config.php)) diff --git a/commands/events/iss.js b/commands/events/iss.js new file mode 100644 index 00000000..1425d0d2 --- /dev/null +++ b/commands/events/iss.js @@ -0,0 +1,32 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class IssCommand extends Command { + constructor(client) { + super(client, { + name: 'iss', + aliases: ['international-space-station'], + group: 'events', + memberName: 'iss', + description: 'Responds with where the Internation Space Station currently is.', + credit: [ + { + name: 'Open Notify', + url: 'http://open-notify.org/', + reason: 'ISS Current Location API', + reasonURL: 'http://open-notify.org/Open-Notify-API/ISS-Location-Now/' + } + ] + }); + } + + async run(msg) { + try { + const { body } = await request.get('http://api.open-notify.org/iss-now.json'); + const position = body.iss_position; + return msg.say(`The ISS is currently at **${position.latitude}, ${position.longitude}**.`); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/events/people-in-space.js b/commands/events/people-in-space.js new file mode 100644 index 00000000..ac77e19e --- /dev/null +++ b/commands/events/people-in-space.js @@ -0,0 +1,45 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { MessageEmbed } = require('discord.js'); +const { removeDuplicates } = require('../../util/Util'); + +module.exports = class PeopleInSpaceCommand extends Command { + constructor(client) { + super(client, { + name: 'people-in-space', + aliases: ['space', 'spacemen', 'astronauts', 'spacewomen'], + group: 'events', + memberName: 'people-in-space', + description: 'Responds with the people currently in space.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Open Notify', + url: 'http://open-notify.org/', + reason: 'People in Space API', + reasonURL: 'http://open-notify.org/Open-Notify-API/People-In-Space/' + } + ] + }); + } + + async run(msg) { + try { + const { body } = await request.get('http://api.open-notify.org/astros.json'); + const crafts = {}; + for (const person of body.people) { + if (crafts[person.craft]) crafts[person.craft].push(person.name); + else crafts[person.craft] = [person.name]; + } + const embed = new MessageEmbed() + .setColor(0x2E528E) + .setImage('https://i.imgur.com/m3ooNfl.jpg'); + for (const [craft, people] of Object.entries(crafts)) { + embed.addField(`❯ ${craft} (${people.length})`, people.join('\n'), true); + } + return msg.say(`There are currently **${body.number}** people in space!`, embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/image-edit/adorable.js b/commands/image-edit/adorable.js new file mode 100644 index 00000000..ff32aace --- /dev/null +++ b/commands/image-edit/adorable.js @@ -0,0 +1,39 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); + +module.exports = class AdorableCommand extends Command { + constructor(client) { + super(client, { + name: 'adorable', + aliases: ['adorable-avatar'], + group: 'image-edit', + memberName: 'adorable', + description: 'Creates an adorable avatar based on the text you provide.', + clientPermissions: ['ATTACH_FILES'], + credit: [ + { + name: 'Adorable Avatars', + url: 'http://avatars.adorable.io/', + reason: 'API' + } + ], + args: [ + { + key: 'text', + prompt: 'What text should be used for generation?', + type: 'string', + parse: text => encodeURIComponent(text) + } + ] + }); + } + + async run(msg, { text }) { + try { + const { body } = await request.get(`https://api.adorable.io/avatars/285/${text}.png`); + return msg.say({ files: [{ attachment: body, name: 'adorable.png' }] }); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 2a05c8ec..ee879615 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.16.0", + "version": "112.17.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {