From 3c9514a344cecd33ac99ad41115487bef4084259 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 25 Sep 2018 00:27:11 +0000 Subject: [PATCH] Azur Lane Ship Command --- .env.example | 1 + README.md | 3 +- commands/search/azur-lane-ship.js | 63 +++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 commands/search/azur-lane-ship.js diff --git a/.env.example b/.env.example index aca82b25..e4291289 100644 --- a/.env.example +++ b/.env.example @@ -15,6 +15,7 @@ SUCCESS_EMOJI_ID= # API Keys, IDs, and Secrets ALPHA_VANTAGE_KEY= +AZUR_LANE_SHIP_ROOT= CUSTOM_SEARCH_ID= DEVIANTART_ID= DEVIANTART_SECRET= diff --git a/README.md b/README.md index ca48b52d..c88d1b36 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (317) +## Commands (318) ### Utility: * **eval:** Executes JavaScript code. @@ -120,6 +120,7 @@ on the [home server](https://discord.gg/sbMe32W). ### Search: +* **azur-lane-ship:** Responds with information on an Azur Lane ship. * **bulbapedia:** Searches Bulbapedia for your query. * **derpibooru:** Responds with an image from Derpibooru. * **deviantart:** Responds with an image from a DeviantArt section, with optional query. diff --git a/commands/search/azur-lane-ship.js b/commands/search/azur-lane-ship.js new file mode 100644 index 00000000..3a97aa73 --- /dev/null +++ b/commands/search/azur-lane-ship.js @@ -0,0 +1,63 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { stripIndents } = require('common-tags'); +const { AZUR_LANE_SHIP_ROOT } = process.env; + +module.exports = class AzurLaneShipCommand extends Command { + constructor(client) { + super(client, { + name: 'azur-lane-ship', + aliases: ['azure-lane-ship', 'azur-lane', 'azure-lane', 'azur', 'azure'], + group: 'search', + memberName: 'azur-lane-ship', + description: 'Responds with information on an Azur Lane ship.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'ship', + prompt: 'What ship would you like to get information on?', + type: 'string', + parse: ship => encodeURIComponent(ship) + } + ] + }); + } + + async run(msg, { ship }) { + try { + const { body } = await request.get(`${AZUR_LANE_SHIP_ROOT}/${ship}`); + const embed = new MessageEmbed() + .setColor(0x1A1917) + .setAuthor('Azur Lane', 'https://i.imgur.com/KeGXiZA.jpg', 'https://azurlane.yo-star.com') + .setTitle(`${body.names.en} (${body.class} Class)`) + .setURL(body.page_url) + .setThumbnail(body.icon) + .setFooter(`Ship #${body.id}`) + .addField('❯ Construction Time', body.construction_time, true) + .addField('❯ Rarity', body.rarity, true) + .addField('❯ Nationality', body.nationality, true) + .addField('❯ Type', body.type, true) + .addField('❯ Health', body.base.health, true) + .addField('❯ Armor', body.base.armor, true) + .addField('❯ Reload', body.base.reload, true) + .addField('❯ Firepower', body.base.firepower, true) + .addField('❯ Torpedo', body.base.torpedo, true) + .addField('❯ Speed', body.base.speed, true) + .addField('❯ Anti-Air', body.base.anti_air, true) + .addField('❯ Anti-Sub', body.base.anti_sub, true) + .addField('❯ Aviation', body.base.air_power, true) + .addField('❯ Oil Cost', body.base.oil_usage, true) + .addField('❯ Equipment', stripIndents` + ${body.equipment[0].equippable} (${body.equipment[0].efficiency}) + ${body.equipment[1].equippable} (${body.equipment[1].efficiency}) + ${body.equipment[2].equippable} (${body.equipment[2].efficiency}) + `) + .addField('❯ Images', `[Chibi](${body.chibi}), ${body.images.map(img => `[${img.name}](${img.url})`).join(', ')}`); + return msg.embed(embed); + } 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 bc5ba3c5..7d12c96d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "91.11.0", + "version": "91.12.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {