Added the 'crypto' command

This commit is contained in:
ION606
2022-08-18 16:29:47 -07:00
parent 62ea3ecec8
commit 3f2e9c6c53
5 changed files with 91 additions and 3 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ const tutoText = [
"__**AMIME AND MANGA**__\nGet info on your favorite Anime or Manga as a stat-sheet, a fancy embed, or have Selmer Bot describe it to you!\n\n__***COMMANDS***__\n!asearch, !msearch",
"__**GAMES**__\nAt the moment Selmer Bot only offers two games: Trivia and Tic Tac Toe. Both games can be played with other people, but only Trivia can be played solo. Selmer Bot also has a battle game where you can use weapons, potions, attack and defend, but this is still in beta\n\n__***COMMANDS***__\n!help game, !game battle !game tictactoe, !game trivia, !game equip, !game status, !game hp, !game classes, !game quit",
"__**SELMER SPECIFIC**__\nThese commands will probably be found nowhere else!\nThese include quotes (For legal reasons I have to state they aren't real quotes, mostly), as well as varius other things I based on good old Selmer\n\n__***COMMANDS***__\n!arrow, !extracredit, !tuto, !profile, !quotes",
"__**MISCELLANEOUS**__\nThese are the commands that are not really in any of the other categories. Don't be fooled, these are actually some of the most useful commands Selmer Bot has to offer. From playing music to web scraping to memes, I'm sure Selmer Bot has what you're looking for!\n\n__***COMMANDS***__\n!help, !kareoke, !link, !meme, !pickupline, !audio, !react, !scrape, !stocks",
"__**MISCELLANEOUS**__\nThese are the commands that are not really in any of the other categories. Don't be fooled, these are actually some of the most useful commands Selmer Bot has to offer. From playing music to web scraping to memes, I'm sure Selmer Bot has what you're looking for!\n\n__***COMMANDS***__\n!help, !kareoke, !link, !meme, !pickupline, !audio, !react, !scrape, !stocks, !crypto",
"__**DM COMMANDS**__\nThese commands will only work in DM's. All these commands will only work with Selmer Bot Premium (it's on the next page).\nThese features include Reminders (AKA a calendar) and Selmer Bot's own chat AI!\n\n__***COMMANDS***__\n!chat, !startconvo, !endconvo, !premium",
"__**SELMER BOT PREMIUM**__\nUse an AI chat, complete with semi-accurate IRL data, have Selmer Bot remind you of events with an easy-to-use interface and even a clickable calendar on the Selmer Bot website (_www.selmerbot.com_)\n\n__***COMMANDS***__\n!premium, !premium buy, !premium manage, !reminders",
"__**Thank you for completing the Selmer Bot Tutorial!**__\n\nTry out all Selmer Bot's features, play the games and most importantly, have fun!\n\n-The Selmer Bot Team AKA ION606"
+76
View File
@@ -0,0 +1,76 @@
const { Formatters, MessageEmbed } = require('discord.js');
const CoinGecko = require('coingecko-api');
const CoinGeckoClient = new CoinGecko();
//#region Runs at the start to store all coins
const coinlist = new Map();
async function getAllCoins() {
const coinlistraw = await CoinGeckoClient.coins.all();
coinlistraw.data.forEach((coin) => {
const obj = { id: coin.id, symbol: coin.symbol, name: coin.name, img: coin.image.small };
coinlist.set(coin.symbol, obj);
});
}
getAllCoins();
//#endregion
// Formatters.codeBlock
module.exports = {
name: 'crypto',
description: 'Get the prices for most cryptocurrencies!',
async execute(message, args, Discord, Client, bot) {
if (args.length < 1 || args[0] == 'help') {
return message.reply("Please specify at least one cryptocurrency (_ex: !crypto BTC_) or list all currencies (_!crypto list_)");
} else if (args[0] == 'list') {
try {
return new Promise((resolve, reject) => {
let temp = "```";
coinlist.forEach((val, key) => {
temp += `Name: ${val.name}, Symbol: ${key}\n`;
});
temp += "```";
resolve(temp);
}).then((temp) => {
message.reply(temp);
})
} catch (err) {
console.error(err);
return message.reply("Uh Oh! There's been an error!");
}
}
try {
let data = await CoinGeckoClient.exchanges.fetchTickers('bitfinex', {
coin_ids: ['bitcoin', 'ethereum', 'ripple', 'litecoin', 'stellar']
});
var datacc = data.data.tickers.filter(t => t.target == 'USD');
const temp = datacc.filter(t => t.base == args[0]);
const res = temp.length == 0 ? [] : temp[0];
//price: res.last, symbol: base, trust score: trust_score
var obj = coinlist.get(res.base.toLowerCase());
obj.price = res.last;
obj.score = res.trust_score || "N/A";
const embd = new MessageEmbed()
.setTitle(obj.name)
.setAuthor({ name: "Selmer Bot", url: "", iconURL: bot.user.displayAvatarURL() })
.setFields(
{name: "Price", value: `$${obj.price}`},
{name: "Symbol", value: `${obj.symbol}`},
{name: "Trust Score", value: `${obj.score}`},
)
.setThumbnail(obj.img)
.setTimestamp()
.setFooter({ text: 'Selmer Bot uses CoinGecko for cryptocurrency information'});
message.reply({ embeds: [embd] });
} catch (err) {
console.error(err);
return message.reply("Uh Oh! There's been an error!");
}
}
}
+2 -2
View File
@@ -3,8 +3,8 @@ const { Modal, TextInputComponent, MessageActionRow, MessageButton, MessageEmbed
const dateFns = require('date-fns');
const { formatToTimeZone } = require('date-fns-timezone');
const Alpaca = require('@alpacahq/alpaca-trade-api');
const apiKeyId = require('../../config.json').alpKey;
const secretKey = require('../../config.json').alpSec;
const apiKeyId = process.env.alpKey || require('../../config.json').alpKey;
const secretKey = process.env.alpSec || require('../../config.json').alpSec;
const alpaca = new Alpaca({
keyId: apiKeyId,
secretKey: secretKey,
+11
View File
@@ -19,6 +19,7 @@
"axios": "^0.27.2",
"canvas": "^2.9.3",
"cheerio": "^1.0.0-rc.10",
"coingecko-api": "^1.0.10",
"date-fns": "^2.29.2",
"date-fns-timezone": "^0.1.4",
"discord-reply": "^0.1.2",
@@ -1030,6 +1031,11 @@
"node": ">=6"
}
},
"node_modules/coingecko-api": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/coingecko-api/-/coingecko-api-1.0.10.tgz",
"integrity": "sha512-7YLLC85+daxAw5QlBWoHVBVpJRwoPr4HtwanCr8V/WRjoyHTa1Lb9DQAvv4MDJZHiz4no6HGnDQnddtjV35oRA=="
},
"node_modules/color-support": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
@@ -6900,6 +6906,11 @@
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
"optional": true
},
"coingecko-api": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/coingecko-api/-/coingecko-api-1.0.10.tgz",
"integrity": "sha512-7YLLC85+daxAw5QlBWoHVBVpJRwoPr4HtwanCr8V/WRjoyHTa1Lb9DQAvv4MDJZHiz4no6HGnDQnddtjV35oRA=="
},
"color-support": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
+1
View File
@@ -10,6 +10,7 @@
"axios": "^0.27.2",
"canvas": "^2.9.3",
"cheerio": "^1.0.0-rc.10",
"coingecko-api": "^1.0.10",
"date-fns": "^2.29.2",
"date-fns-timezone": "^0.1.4",
"discord-reply": "^0.1.2",