mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-08 15:19:14 +02:00
Search in Stocks
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.4.0",
|
||||
"version": "112.4.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user