diff --git a/commands/random/stocks.js b/commands/random/stocks.js new file mode 100644 index 00000000..c67d44b1 --- /dev/null +++ b/commands/random/stocks.js @@ -0,0 +1,56 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const { ALPHA_VANTAGE_KEY } = process.env; + +module.exports = class StocksCommand extends Command { + constructor(client) { + super(client, { + name: 'stocks', + group: 'random', + memberName: 'stocks', + description: 'Get the current stocks for a symbol.', + args: [ + { + key: 'symbol', + prompt: 'What symbol would you like to get the stocks for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { symbol } = args; + try { + const { body } = await snekfetch + .get('https://www.alphavantage.co/query') + .query({ + function: 'TIME_SERIES_INTRADAY', + symbol, + interval: '1min', + apikey: ALPHA_VANTAGE_KEY + }); + if (body['Error Message']) return msg.say('Could not find any results.'); + const data = Object.values(body['Time Series (1min)'])[0]; + const embed = new MessageEmbed() + .setTitle(`Stocks for Symbol ${symbol}`) + .setColor(0x9797FF) + .addField('❯ Open', + `$${data['1. open']}`, true) + .addField('❯ Close', + `$${data['4. close']}`, true) + .addField('❯ Volume', + data['5. volume'], true) + .addField('❯ High', + `$${data['2. high']}`, true) + .addField('❯ Low', + `$${data['3. low']}`, true) + .addField('❯ Last Updated', + new Date(body['Meta Data']['Last Refreshed']).toDateString(), true); + return msg.embed(embed); + } catch (err) { + return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/commands/random/xkcd.js b/commands/random/xkcd.js index 8d28d01e..1e20e08d 100644 --- a/commands/random/xkcd.js +++ b/commands/random/xkcd.js @@ -50,7 +50,7 @@ module.exports = class XKCDCommand extends Command { return msg.embed(embed); } const choice = parseInt(type, 10); - if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Invalid number.'); + if (isNaN(choice) || current.body.num < choice || choice < 1) return msg.say('Could not find any results.'); const { body } = await snekfetch .get(`https://xkcd.com/${choice}/info.0.json`); const embed = new MessageEmbed() diff --git a/package.json b/package.json index 78be47e5..f6726df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "35.2.1", + "version": "35.3.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Command.js b/structures/Command.js index d0eae721..cb15945b 100644 --- a/structures/Command.js +++ b/structures/Command.js @@ -13,7 +13,7 @@ class XiaoCommand extends Command { hasPermission(msg) { const baseCheck = super.hasPermission(msg); - if (!baseCheck) return baseCheck; + if (!baseCheck || typeof baseCheck === 'string') return baseCheck; if (this.ownerOnly && !this.client.isOwner(msg.author)) { return `The \`${this.name}\` command can only be used by the bot owner.`; }