mirror of
https://github.com/ION606/selmerBot.git
synced 2026-06-05 23:06:14 +00:00
Transitioned all Misc, audio, Selmer Specific, admin, anime/manga, and inventory commands to Slash Command format. The RSS and reactionrole commands are still broken and all game commands are still in message format due to compications
This commit is contained in:
+29
-28
@@ -1,4 +1,4 @@
|
||||
const { Modal, TextInputComponent, MessageActionRow, MessageButton, MessageEmbed, Interaction } = require('discord.js');
|
||||
const { Constants, MessageEmbed, Interaction } = require('discord.js');
|
||||
|
||||
const dateFns = require('date-fns');
|
||||
const { formatToTimeZone } = require('date-fns-timezone');
|
||||
@@ -13,7 +13,7 @@ const alpaca = new Alpaca({
|
||||
});
|
||||
|
||||
//This is the same as making the following request: https://data.alpaca.markets/v2/stocks/snapshots?symbols={stock_symbols_here}
|
||||
async function getStockData(bot, message, args, stock) {
|
||||
async function getStockData(bot, interaction, stock, type, after) {
|
||||
try {
|
||||
const snapshotPromise = alpaca.getSnapshot(stock);
|
||||
|
||||
@@ -22,7 +22,7 @@ async function getStockData(bot, message, args, stock) {
|
||||
.setAuthor({ name: "Selmer Bot", url: "", iconURL: bot.user.displayAvatarURL() })
|
||||
.setFooter({ text: 'Selmer Bot uses Alpaca for stock information'})
|
||||
|
||||
if (args[1] == 'trade') {
|
||||
if (type) {
|
||||
const lt = snapshot.LatestTrade;
|
||||
embd.setTitle(`${stock} Latest Trade`)
|
||||
.setTimestamp(lt.Timestamp)
|
||||
@@ -33,9 +33,9 @@ async function getStockData(bot, message, args, stock) {
|
||||
//This will always be IEX, as it is the only exchange the free version offers
|
||||
{name: 'Exchange', value: `IEX (${lt.Exchange})`},
|
||||
)
|
||||
} else if (args[1] == 'quote') {
|
||||
if (args[2] == 'after') {
|
||||
return message.reply("Due to the markets not being open, there is no quote data available!");
|
||||
} else if (type) {
|
||||
if (after) {
|
||||
return interaction.reply("Due to the markets not being open, there is no quote data available!");
|
||||
}
|
||||
const lq = snapshot.LatestQuote;
|
||||
embd.setTitle(`${stock} Latest Quote`)
|
||||
@@ -49,7 +49,7 @@ async function getStockData(bot, message, args, stock) {
|
||||
//This will always be IEX, as it is the only exchange the free version offers
|
||||
{name: 'Exchange', value: `IEX (${lq.Exchange})`},
|
||||
)
|
||||
} else if (args[1] == 'bars') {
|
||||
} else if (type) {
|
||||
const mb = snapshot.MinuteBar;
|
||||
const db = snapshot.DailyBar;
|
||||
const pdb = snapshot.PrevDailyBar;
|
||||
@@ -61,23 +61,22 @@ async function getStockData(bot, message, args, stock) {
|
||||
{name: 'Day Bar (Yesterday)', value: `Open Price: ${pdb.OpenPrice},\nClose Price: ${pdb.ClosePrice},\nHigh Price: ${pdb.HighPrice},\nLow Price: ${pdb.LowPrice},\nVolume: ${pdb.Volume},\nCount: ${pdb.TradeCount},\nVWAP: ${pdb.VWAP}`},
|
||||
)
|
||||
} else {
|
||||
return message.reply("The command format is: _!stocks <stock_name, 'hours'> <trade, quote, bars> [after]_");
|
||||
return interaction.reply("The command format is: _/stocks <stock_name, 'hours'> <trade, quote, bars> [after]_");
|
||||
}
|
||||
|
||||
message.reply({embeds: [embd]});
|
||||
interaction.reply({embeds: [embd]});
|
||||
})
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
message.reply("Uh Oh, there's been an error!");
|
||||
interaction.reply("Uh Oh, there's been an error!");
|
||||
}
|
||||
}
|
||||
|
||||
function getData(bot, message, args) {
|
||||
var stock;
|
||||
if (args.length < 1) {
|
||||
return message.reply("Please specify a stock (ex: AAPL, GOOG, etc)")
|
||||
} else { stock = args[0];}
|
||||
|
||||
function getData(bot, interaction) {
|
||||
const args = interaction.options.data;
|
||||
const stock = args.filter((arg) => { return (arg.name == 'name')})[0].value;
|
||||
const type = args.filter((arg) => { return (arg.name == 'type')})[0].value;
|
||||
const after = (args.length > 2 && args.filter((arg) => { return (arg.name == 'after')})[0].value);
|
||||
|
||||
const format = `yyyy-MM-dd HH:mm:ss`;
|
||||
const date = dateFns.format(new Date(), format);
|
||||
@@ -90,17 +89,17 @@ function getData(bot, message, args) {
|
||||
end: date
|
||||
}).then((calendars) => {
|
||||
let temp;
|
||||
if (clock.is_open || args[2] == 'after') {
|
||||
if (args[0] == 'hours') {
|
||||
if (clock.is_open || after) {
|
||||
if (stock == 'hours') {
|
||||
temp = `The markets opened at ${calendars[0].open} and will close at ${calendars[0].close} on ${date}.`;
|
||||
return message.reply(temp);
|
||||
return interaction.reply(temp);
|
||||
}
|
||||
getStockData(bot, message, args, stock);
|
||||
getStockData(bot, interaction, stock, type, after);
|
||||
} else {
|
||||
// `The market is currently ${clock.is_open ? 'open.' : 'closed.'}`
|
||||
//May be innacurate?
|
||||
temp = `_The markets closed at \`${calendars[0].close}\` and will open again at \`${calendars[0].open}\` on \`${dateFns.format((new Date()).setDate(new Date().getDate() + 1), 'yyyy-MM-dd')}\`.\nTo get the last snapshot before market closure, add the \`after\` keyword to the end of your command (trade and bars ONLY), ex: !stocks GOOG bars after_`;
|
||||
return message.reply(temp);
|
||||
temp = `_The markets closed at \`${calendars[0].close}\` and will open again at \`${calendars[0].open}\` on \`${dateFns.format((new Date()).setDate(new Date().getDate() + 1), 'yyyy-MM-dd')}\`.\nTo get the last snapshot before market closure, add the \`after\` keyword to the end of your command (trade and bars ONLY), ex: /stocks GOOG bars after_`;
|
||||
return interaction.reply(temp);
|
||||
}
|
||||
});
|
||||
})
|
||||
@@ -111,10 +110,12 @@ function getData(bot, message, args) {
|
||||
module.exports = {
|
||||
name: 'stocks',
|
||||
description: "Have Selmer Bot give you \"current\" stock prices",
|
||||
async execute(message, args, Discord, Client, bot) {
|
||||
if (args[0] == 'help' || args.length < 1) {
|
||||
return message.reply("The command format is: _!stocks <stock_name, 'hours'> <trade, quote, bars> [after]_");
|
||||
}
|
||||
getData(bot, message, args);
|
||||
}
|
||||
async execute(interaction, Discord, Client, bot) {
|
||||
getData(bot, interaction);
|
||||
},
|
||||
options: [
|
||||
{name: 'name', description: 'the stock name or "hours" for market hours', type: Constants.ApplicationCommandOptionTypes.STRING, required: true},
|
||||
{name: 'type', description: 'The type of data to present', type: Constants.ApplicationCommandOptionTypes.STRING, required: true, choices: [ { name: 'trade', value: 'trade' }, { name: 'quote', value: 'quote' }, {name: 'bars', value: 'bars'}]},
|
||||
{name: 'after', description: 'If the markets are closed, get the last entry', type: Constants.ApplicationCommandOptionTypes.BOOLEAN, required: false},
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user