This commit is contained in:
Daniel Odendahl Jr
2017-09-05 00:30:28 +00:00
parent a1915c78ae
commit cda61f1545
4 changed files with 59 additions and 3 deletions
+56
View File
@@ -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!`);
}
}
};
+1 -1
View File
@@ -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()
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "35.2.1",
"version": "35.3.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {
+1 -1
View File
@@ -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.`;
}