Skip to content

Commit

Permalink
Added the price command.
Browse files Browse the repository at this point in the history
This is a temporary command, it is being overhauled in the near future once other changes outside of this project have taken place - which are needed to support this feature to it's planned effect.
  • Loading branch information
AdamT20054 committed Sep 17, 2023
1 parent fface67 commit f19c365
Show file tree
Hide file tree
Showing 10 changed files with 633 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ dist
# TernJS port file
.tern-port
/OldCodebase/
/src/utils/commandutils/price/priceLinks.json
417 changes: 417 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/AdamT20054/VyFi#readme",
"dependencies": {
"axios": "^1.5.0",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1"
}
Expand Down
67 changes: 67 additions & 0 deletions src/commands/information/price.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const {PermissionFlagsBits} = require('discord.js');
const axios = require('axios');

const priceButtons = require('../../utils/commandutils/price/priceButtons');
const priceEmbeds = require('../../utils/commandutils/price/priceEmbeds');

// THIS FILE IS TEMPORARY, IT WILL BE REPLACED AND UPDATED VERY SOON.
// The changes required to get this command "flush" with the rest of the
// project require me to make a few changes to my database to accommodate
// the new features. I will be working on this soon, but for now, this
// command will be a placeholder.

module.exports = {
name: 'price',
description: "Get VyFi's current price and common conversions!",
devOnly: false,
testOnly: true,
deleted: false,
options: [],
permissionsRequired: [PermissionFlagsBits.SendMessages],
botPermissions: [PermissionFlagsBits.SendMessages],

callback: async (client, interaction) => {

const temp = await axios.get(`hx`).catch(console.error);
const priceUSD = temp.data[`8x`].priceUSD.toFixed(2);
const priceADA = 0;

// For ADA price, query mariaDB for the last price. Set to 0 while this feature is implemented.
// This Feature currently requires me to edit the database manager functions.

interaction.reply({
embeds: [priceEmbeds.buildPriceEmbed(priceUSD, priceADA)],
components: [priceButtons.buildButtons(false, null)]
}).then((m) => {
const collector = m.createMessageComponentCollector({time: 60000, max: 4});

collector.on('collect', async (i) => {
if (!i.isButton()) return;

await i.deferUpdate();
if (i.user.id !== interaction.user.id) return i.followUp({
content: `These buttons aren't for you!`,
ephemeral: true
});
if (i.customId === 'refresh') {
const temp = await axios.get(`x`).catch(console.error);
const priceUSD = temp.data[`x`].priceUSD.toFixed(2);
const priceADA = 0;

return i.editReply({
embeds: [priceEmbeds.buildPriceEmbed(priceUSD, priceADA)],
}).catch(function () {
})
}
await m.interaction.editReply({components: [priceButtons.buildButtons(true, i.customId)]})

return i.followUp({
content: `Thanks for using Vyfi!`,
ephemeral: true
}).catch(function () {
});

});
})
}
};
23 changes: 23 additions & 0 deletions src/utils/commandutils/price/priceButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {ButtonBuilder, ButtonStyle, ActionRowBuilder} = require('discord.js');
const {gettingStartedURL, websiteURL} = require('./priceLinks.json');

function buildButtons(toggle = false, choice) {
return new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel('Website')
.setURL(websiteURL)
.setStyle(ButtonStyle.Link),
new ButtonBuilder()
.setLabel('Getting Started')
.setURL(gettingStartedURL)
.setStyle(ButtonStyle.Link),
new ButtonBuilder()
.setLabel('Refresh Price')
.setCustomId('refresh')
.setStyle(toggle === true && choice === 'red' ? 'Secondary' : 'Danger')
)
}

module.exports = {
buildButtons
};
22 changes: 22 additions & 0 deletions src/utils/commandutils/price/priceEmbeds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {EmbedBuilder} = require('discord.js');
const {thumbnailURL, footerIconURL, githubURL} = require('./priceLinks.json');

function buildPriceEmbed(priceUSD, priceADA) {
return new EmbedBuilder()
.setTitle('VyFi Price')
.setFields(
{name: "Current USD Price", value: `$${priceUSD}`},
{name: "Current ADA Price", value: `${priceADA}₳`},
{name: "Total Supply", value: `450,000,000VyFi`},
)
.setColor('#03fcdb')
.setThumbnail(thumbnailURL)
.setTimestamp()
.setFooter({text: githubURL, iconURL: footerIconURL});
}


module.exports = {
buildPriceEmbed

};
7 changes: 7 additions & 0 deletions src/utils/commandutils/price/priceLinks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"gettingStartedURL": "https://docs.vyfi.io/getting-started",
"websiteURL": "https://vyfi.io",
"thumbnailURL": "https://app.vyfi.io/images/vyfi-logo.png",
"footerIconURL": "https://avatars.githubusercontent.com/u/78691968",
"githubURL": "https://github.com/AdamT20054/VyFi"
}
3 changes: 3 additions & 0 deletions src/utils/getPrices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// make a few functions to fetch prices from Mariadb or any other APIs needed

// create database connector in data/database/utils

0 comments on commit f19c365

Please sign in to comment.