Ridiculous

This commit is contained in:
Daniel Odendahl Jr
2017-08-22 22:39:53 +00:00
parent 1938b65786
commit 2a0ddcd31c
2 changed files with 57 additions and 1 deletions
+56
View File
@@ -0,0 +1,56 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const moment = require('moment');
const { ALHPA_VANTAGE_KEY } = process.env;
module.exports = class StocksCommand extends Command {
constructor(client) {
super(client, {
name: 'stocks',
aliases: ['stock'],
group: 'random',
memberName: 'stocks',
description: 'Responds with the stock information for the symbol you specify.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'symbol',
prompt: 'What is the symbol you would like to get data for?',
type: 'string'
}
]
});
}
async run(msg, args) {
const { symbol } = args;
const { body } = await snekfetch
.get('https://www.alphavantage.co/query')
.query({
function: 'TIME_SERIES_INTRADAY',
symbol,
interval: '1min',
apikey: ALHPA_VANTAGE_KEY
});
if (body['Error Message']) return msg.say('Invalid Symbol.');
const data = body['Time Series (1min)'][Object.keys(body['Time Series (1min)'])[0]];
const embed = new MessageEmbed()
.setColor()
.setTitle(symbol.toUpperCase())
.setTimestamp()
.addField(' Open',
`$${parseFloat(data['1. open'])}`, true)
.addField(' Close',
`$${parseFloat(data['4. close'])}`, true)
.addField(' Volume',
data['5. volume'], true)
.addField(' High',
`$${parseFloat(data['2. high'])}`, true)
.addField(' Low',
`$${parseFloat(data['3. low'])}`, true)
.addField(' Last Updated',
moment(Object.keys(body['Time Series (1min)'])[0]).format('MM-DD-YYYY hh:mm'), true);
return msg.embed(embed);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "31.0.2",
"version": "31.1.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {