Skip to content

Commit

Permalink
Updated deprecated functions and linted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Mar 9, 2022
1 parent 1758f8f commit 139da8a
Show file tree
Hide file tree
Showing 21 changed files with 987 additions and 777 deletions.
41 changes: 41 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"windows"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"args": "none"
}
],
"no-constant-condition": [
"error",
{
"checkLoops": false
}
]
}
}
34 changes: 17 additions & 17 deletions commands/categories.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const tokens = require('../index.js')
const { MessageEmbed } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

/**
* Function to provide a list of categories for the given game
Expand All @@ -10,15 +10,15 @@ module.exports = {
* Builds /categories [string:game]
*/
data: new SlashCommandBuilder()
.setName('categories')
.setDescription('Shows the categories/variables for the provided game.')
.setName("categories")
.setDescription("Shows the categories/variables for the provided game.")
.addStringOption(option =>
option.setName('game')
.setDescription('Game to show categories')
option.setName("game")
.setDescription("Game to show categories")
.setRequired(true)
),
async execute(interaction) {
const game = interaction.options.get('game').value.toLowerCase();
async execute(interaction) {
const game = interaction.options.get("game").value.toLowerCase();
// Fetches the categories
const { data } = await tokens.fetch(`https://www.speedrun.com/api/v1/games?abbreviation=${game}&embed=categories.variables`);
// Checks if game exists
Expand All @@ -27,36 +27,36 @@ module.exports = {
}
const [dataArr] = data;
const embed = new MessageEmbed()
.setColor('118855')
.setColor("118855")
.setTitle(dataArr.names.international)
.setURL(dataArr.weblink)
.setThumbnail(dataArr.assets["cover-large"].uri)
.setThumbnail(dataArr.assets["cover-large"].uri);
// Iterates through all the categories for the game
let size = 0;
for (const category of dataArr.categories.data) {
let variables = '';
let variables = "";
// Checks if variables exist
if (category.variables.data[0]) {
let varArr = category.variables.data[0].values.values;
// Gets alll the variablrd and adds them to the string
varArr = Object.values(varArr);
for (let j = 0; j < varArr.length; j++) {
variables += varArr[j].label + ', ';
variables += varArr[j].label + ", ";
}
variables = variables.slice(0, -2);
} else {
variables = 'None';
variables = "None";
}
// Category for embed
const string = '**Category:** ' + category.name + '** - id:** ' + category.id
const string = "**Category:** " + category.name + "** - id:** " + category.id;
// Variables for embed
const string2 = ' **Variables:** ' + variables + '\n';
const string2 = " **Variables:** " + variables + "\n";
size += string.length + string2.length;
if(size > 6000) {
break;
}
embed.addField(string, string2);
}
return await interaction.editReply({ embeds: [embed] });
},
},
};
40 changes: 20 additions & 20 deletions commands/dream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
* Function to provide a simulation of Dream's pearl/blaze rod odds.
Expand All @@ -9,22 +9,22 @@ module.exports = {
* Builds /categories (integer:simulations)
*/
data: new SlashCommandBuilder()
.setName('dream')
.setDescription('Simulates Dream\'s pearl and blaze rod odds.')
.setName("dream")
.setDescription("Simulates Dream's pearl and blaze rod odds.")
.addIntegerOption(option =>
option.setName('simulations')
.setDescription('Number of simulations to run (Max 100,000')
option.setName("simulations")
.setDescription("Number of simulations to run (Max 100,000")
),
async execute(interaction) {
let sim = interaction.options.get('simulations');
async execute(interaction) {
let sim = interaction.options.get("simulations");
// If the number of simulations was not specified then set sim to 1
if(!sim) {
sim = 1;
} else {
sim = sim.value;
}
if(sim > 100000) {
return await interaction.editReply('Too many simulations (' + sim + ')');
return await interaction.editReply("Too many simulations (" + sim + ")");
}
// Max pearls
let pMax = 0;
Expand Down Expand Up @@ -56,18 +56,18 @@ module.exports = {
rTotal += rCount;
}
// Compares pearls to Dream
const difference = pMax >= 42 ? '+' + pMax - 42 : pMax - 42;
const difference = pMax >= 42 ? "+" + pMax - 42 : pMax - 42;
// Compares rods to Dream
const difference2 = rMax >= 211 ? '+' + rMax - 211 : rMax - 211;
const difference2 = rMax >= 211 ? "+" + rMax - 211 : rMax - 211;
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Your Results:')
.addField('Number of simulations: ', String(sim))
.addField('Average number of pearl trades: ', String(pTotal / sim))
.addField('Average number of rods: ', String(rTotal / sim))
.addField('Max number of pearl trades: ' + pMax + '/262', 'Number of pearl trades (Dream): 42/262')
.addField('Max number of rods: ' + rMax + '/305', 'Number of rods (Dream): 211/305')
.setFooter('Difference: ' + difference + '/' + difference2)
.setColor("118855")
.setTitle("Your Results:")
.addField("Number of simulations: ", String(sim))
.addField("Average number of pearl trades: ", String(pTotal / sim))
.addField("Average number of rods: ", String(rTotal / sim))
.addField("Max number of pearl trades: " + pMax + "/262", "Number of pearl trades (Dream): 42/262")
.addField("Max number of rods: " + rMax + "/305", "Number of rods (Dream): 211/305")
.setFooter({ text: "Difference: " + difference + "/" + difference2 });
await interaction.editReply({ embeds: [embed] });
},
},
};
40 changes: 20 additions & 20 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
* Function to provide help for slash commands.
Expand All @@ -9,24 +9,24 @@ module.exports = {
* Builds /help
*/
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Provides a list of commands and descriptions.'),
async execute(interaction) {
.setName("help")
.setDescription("Provides a list of commands and descriptions."),
async execute(interaction) {
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Help')
.setThumbnail('https://www.speedrun.com/images/1st.png')
.addField('/help', 'Shows this help message.')
.addField('/hypixel', 'Provides helpful links for Hypixel Speedruns')
.addField('/link <game>', 'Sends a link to the provided game.')
.addField('/categories <game>', 'Shows the categories/variables for the provided game.')
.addField('/search <keyword> (page)', 'Searches for games containing the keyword(s).')
.addField('/leaderboard <game>', 'Provides a leaderboard for the given game.')
.addField('/verified <user>', 'Provides the number of runs verified by the given user.')
.addField('/queuelength <game>', 'Provides the number of unverified runs for the given game.')
.addField('/dream (simulations)', 'Simulates Dream\'s pearl and blaze rod odds.')
.addField('/ping', 'Provides bot response time.')
await interaction.editReply('Sending you help!');
.setColor("118855")
.setTitle("Help")
.setThumbnail("https://www.speedrun.com/images/1st.png")
.addField("/help", "Shows this help message.")
.addField("/hypixel", "Provides helpful links for Hypixel Speedruns")
.addField("/link <game>", "Sends a link to the provided game.")
.addField("/categories <game>", "Shows the categories/variables for the provided game.")
.addField("/search <keyword> (page)", "Searches for games containing the keyword(s).")
.addField("/leaderboard <game>", "Provides a leaderboard for the given game.")
.addField("/verified <user>", "Provides the number of runs verified by the given user.")
.addField("/queuelength <game>", "Provides the number of unverified runs for the given game.")
.addField("/dream (simulations)", "Simulates Dream's pearl and blaze rod odds.")
.addField("/ping", "Provides bot response time.");
await interaction.editReply("Sending you help!");
await interaction.followUp({ embeds: [embed], ephemeral: true });
},
},
};
Loading

0 comments on commit 139da8a

Please sign in to comment.