diff --git a/commands/help.js b/commands/help.js index 2948f9a..5aafef5 100644 --- a/commands/help.js +++ b/commands/help.js @@ -16,7 +16,8 @@ module.exports = { **!random** - Selects a random article: *!random* **!random category** - Selects a random article by category: *!random sports* **!answer** - Instant Live Search: *!answer salesforce* - **!slang** - Urban Dictionary Search: *!answer slang* + **!slang** - Urban Dictionary Search: *!slang slang* + **!stock** - AlphaVantage Stock Search: *!stock IBM* ` ); } diff --git a/commands/stock.js b/commands/stock.js new file mode 100644 index 0000000..3413e83 --- /dev/null +++ b/commands/stock.js @@ -0,0 +1,32 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'slang', + description: 'Slang', + async execute(message, args) { + try { + if (args.length < 1) { + message.reply(`Please use in !slang [question] format`); + return; + } + var question = encodeURIComponent(args.join(" ")); + + var stockData = await libFlayer.getStock(question); + message.reply(`**Search Stock Info**: + symbol: ${stockData.symbol} + open: ${stockData.open} + high: ${stockData.high} + low: ${stockData.low} + price: ${stockData.price} + volume: ${stockData.volume} + latest: ${stockData.latest} + previous: ${stockData.previous} + change: ${stockData.change} + percent: ${stockData.percent} + `); + } catch (e) { + message.reply(e.toString()); + } + + } +}; \ No newline at end of file diff --git a/libFlayer.js b/libFlayer.js index 3e2d09a..6a215b4 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -266,6 +266,49 @@ exports.getSlang = async function (question) { return slangData; } +exports.getStock = async function (stock) { + + var answerURL = `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${stock}&interval=5min&apikey=demo`; + console.log(answerURL); + stockData = { + symbol: `Not Found`, + open: ``, + high: ``, + low: ``, + price: ``, + volume: ``, + latest: ``, + previous: ``, + change: ``, + percent: `` + } + await axios.get(answerURL) + .then(response => { + //console.log(response.data.list[0]); + + stockData = { + symbol: `${unescape(response.data["Global Quote"]['01. symbol'])}`, + open: `${unescape(response.data["Global Quote"]['02. open'])}`, + high: `${unescape(response.data["Global Quote"]['03. high'])}`, + low: `${unescape(response.data["Global Quote"]['04. low'])}`, + price: `${unescape(response.data["Global Quote"]['05. price'])}`, + volume: `${unescape(response.data["Global Quote"]['06. volume'])}`, + latest: `${unescape(response.data["Global Quote"]['07. latest trading day'])}`, + previous: `${unescape(response.data["Global Quote"]['08. previous close'])}`, + change: `${unescape(response.data["Global Quote"]['09. change'])}`, + percent: `${unescape(response.data["Global Quote"]['10. change percent'])}` + } + + return stockData; + }) + .catch(error => { + console.log(error); + }); + return stockData; +} + + + /** * getSources - Returns libFlayer feed sources * @constructor