diff --git a/README.md b/README.md index 5d7cab6c..0fc8cd9b 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ Total: 365 * **soundcloud:** Searches SoundCloud for your query. * **stack-overflow:** Searches Stack Overflow for your query. * **steam:** Searches Steam for your query. -* **stocks:** Responds with the current stocks for a specific symbol. +* **stocks:** Responds with the current stocks for a company. * **tenor:** Searches Tenor for your query. * **tumblr:** Responds with information on a Tumblr blog. * **tv-show:** Searches TMDB for your query, getting TV show results. @@ -1041,6 +1041,8 @@ here. * frame ([Image](http://www.aljanh.net/frame-wallpapers/1508614706.html)) - [xkcd](https://xkcd.com/) * xkcd ([API](https://xkcd.com/json.html)) +- [Yahoo](https://www.yahoo.com/) + * stocks (Finance API) - [YGOPRODECK](https://ygoprodeck.com/) * yu-gi-oh ([API](https://db.ygoprodeck.com/api-guide/)) - [YorkAARGH](https://github.com/YorkAARGH) diff --git a/commands/search/stocks.js b/commands/search/stocks.js index f9393f54..3327406c 100644 --- a/commands/search/stocks.js +++ b/commands/search/stocks.js @@ -11,39 +11,46 @@ module.exports = class StocksCommand extends Command { aliases: ['stock', 'alpha-vantage'], group: 'search', memberName: 'stocks', - description: 'Responds with the current stocks for a specific symbol.', + description: 'Responds with the current stocks for a company.', clientPermissions: ['EMBED_LINKS'], credit: [ { name: 'Alpha Vantage', url: 'https://www.alphavantage.co/', reason: 'API' + }, + { + name: 'Yahoo', + url: 'https://www.yahoo.com/', + reason: 'Finance API' } ], args: [ { - key: 'symbol', - prompt: 'What symbol would you like to get the stocks of?', + key: 'query', + prompt: 'What company would you like to get the stocks of?', type: 'string' } ] }); } - async run(msg, { symbol }) { + async run(msg, { query }) { try { + const company = await this.search(query); + if (!company) return msg.say('Could not find any results.'); const { body } = await request .get('https://www.alphavantage.co/query') .query({ function: 'TIME_SERIES_INTRADAY', - symbol, + symbol: company.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.toUpperCase()}`) + .setTitle(`Stocks for ${company.name} (${symbol.toUpperCase()})`) .setColor(0x9797FF) .setFooter('Last Updated') .setTimestamp(new Date(body['Meta Data']['3. Last Refreshed'])) @@ -58,4 +65,16 @@ module.exports = class StocksCommand extends Command { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } + + async search(query) { + const { body } = await request + .get('http://d.yimg.com/autoc.finance.yahoo.com/autoc') + .query({ + query, + region: 1, + lang: 'en' + }); + if (!body.ResultSet.Result.length) return null; + return body.ResultSet.Result[0]; + } }; diff --git a/package.json b/package.json index 7de9b292..f43932af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.4.0", + "version": "112.4.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {