Skip to content

Commit

Permalink
Merge pull request #64 from Nick-NCSU/update-discordjs-14
Browse files Browse the repository at this point in the history
updated old commands
  • Loading branch information
Nick-NCSU authored Aug 7, 2022
2 parents 386edb9 + 1f35ee9 commit 3b09567
Show file tree
Hide file tree
Showing 19 changed files with 512 additions and 497 deletions.
12 changes: 7 additions & 5 deletions commands/categories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

Expand Down Expand Up @@ -26,14 +26,14 @@ module.exports = {
return await interaction.editReply(`No results found for **${game}**.`);
}
const [dataArr] = data;
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setTitle(dataArr.names.international)
.setURL(dataArr.weblink)
.setThumbnail(dataArr.assets["cover-large"].uri);
// Iterates through all the categories for the game
let size = 0;
for (const category of dataArr.categories.data) {
for (const category of dataArr.categories.data.slice(0, 25)) {
let variables = "";
// Checks if variables exist
if (category.variables.data[0]) {
Expand All @@ -55,7 +55,9 @@ module.exports = {
if(size > 6000) {
break;
}
embed.addField(string, string2);
embed.addFields([
{ name: string, value: string2, }
]);
}
return await interaction.editReply({ embeds: [embed] });
},
Expand Down
18 changes: 10 additions & 8 deletions commands/dream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
Expand Down Expand Up @@ -59,14 +59,16 @@ module.exports = {
const difference = pMax >= 42 ? "+" + pMax - 42 : pMax - 42;
// Compares rods to Dream
const difference2 = rMax >= 211 ? "+" + rMax - 211 : rMax - 211;
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.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")
.addFields([
{ name: "Number of simulations: ", value: String(sim) },
{ name: "Average number of pearl trades: ", value: String(pTotal / sim ) },
{ name: "Average number of rods: ", value: String(rTotal / sim ) },
{ name: "Max number of pearl trades: " + pMax + "/262", value: "Number of pearl trades (Dream) 42/262" },
{ name: "Max number of rods: " + rMax + "/305", value: "Number of rods (Dream) 211/305" }
])
.setFooter({ text: "Difference: " + difference + "/" + difference2 });
await interaction.editReply({ embeds: [embed] });
},
Expand Down
28 changes: 15 additions & 13 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
Expand All @@ -12,20 +12,22 @@ module.exports = {
.setName("help")
.setDescription("Provides a list of commands and descriptions."),
async execute(interaction) {
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.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.");
.addFields([
{ name: "/help", value: "Shows this help message." },
{ name: "/hypixel", value: "Provides helpful links for Hypixel Speedruns" },
{ name: "/link <game>", value: "Sends a link to the provided game." },
{ name: "/categories <game>", value: "Shows the categories/variables for the provided game." },
{ name: "/search <keyword> (page)", value: "Searches for games containing the keyword(s)." },
{ name: "/leaderboard <game>", value: "Provides a leaderboard for the given game." },
{ name: "/verified <user>", value: "Provides the number of runs verified by the given user." },
{ name: "/queuelength <game>", value: "Provides the number of unverified runs for the given game." },
{ name: "/dream (simulations)", value: "Simulates Dream's pearl and blaze rod odds." },
{ name: "/ping", value: "Provides bot response time." }
]);
await interaction.editReply("Sending you help!");
await interaction.followUp({ embeds: [embed], ephemeral: true });
},
Expand Down
18 changes: 9 additions & 9 deletions commands/hypixel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageActionRow, MessageSelectMenu, MessageButton } = require("discord.js");
const { ActionRowBuilder, SelectMenuBuilder, ButtonBuilder, InteractionType, ButtonStyle } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
Expand All @@ -13,10 +13,10 @@ module.exports = {
.setDescription("Provides helpful links for Hypixel Speedruns"),
async execute(interaction) {
// Initial running of the command
if(interaction.isCommand()) {
const row = new MessageActionRow()
if(interaction.type === InteractionType.ApplicationCommand) {
const row = new ActionRowBuilder()
.addComponents(
new MessageSelectMenu()
new SelectMenuBuilder()
.setCustomId("type")
.setPlaceholder("Nothing selected")
.addOptions([
Expand Down Expand Up @@ -171,9 +171,9 @@ module.exports = {
];
break;
}
const row = new MessageActionRow()
const row = new ActionRowBuilder()
.addComponents(
new MessageSelectMenu()
new SelectMenuBuilder()
.setCustomId("link")
.setPlaceholder("Nothing selected")
.addOptions(options),
Expand Down Expand Up @@ -256,11 +256,11 @@ module.exports = {
url = "https://twitter.com/speedruncom";
break;
}
const row = new MessageActionRow()
const row = new ActionRowBuilder()
.addComponents(
new MessageButton()
new ButtonBuilder()
.setLabel(interaction.values[0])
.setStyle("LINK")
.setStyle(ButtonStyle.Link)
.setURL(url),
);
await interaction.update({ content: interaction.values[0] + " Link:", components: [row] });
Expand Down
60 changes: 31 additions & 29 deletions commands/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const tokens = require("../index.js");
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
Expand All @@ -19,15 +19,15 @@ module.exports = {
)
.addBooleanOption(option =>
option.setName("misc")
.setDescription("Include misc categories? Default: true")
.setDescription("Include misc categories? Default: true")
)
.addBooleanOption(option =>
option.setName("fullgame")
.setDescription("Include Full Game Categories? Default: true")
.setDescription("Include Full Game Categories? Default: true")
)
.addBooleanOption(option =>
option.setName("ils")
.setDescription("Include Individual Levels? Default: true")
.setDescription("Include Individual Levels? Default: true")
),
async execute(interaction) {
// From rsp via https://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript
Expand Down Expand Up @@ -135,18 +135,20 @@ module.exports = {
}
}

if(!game.startsWith('hypixel_') && count + count2 > 500) {
if(!game.startsWith("hypixel_") && count + count2 > 500) {
return await interaction.editReply(`Game ${game} has too many categories. Number of categories: ${count + count2}.`);
}

let date = new Date().toISOString().slice(0, 10);
let embed = new MessageEmbed()
.setColor("118855")
let embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Leaderboard for " + game + ":")
.setThumbnail(data.assets["cover-large"].uri)
.setFooter({ text: date })
.addField("Full Game Progress:", `${progress}/${count}`)
.addField("Individual Levels Progress:", `${progress2}/${count2}`);
.addFields([
{ name: "Full Game Progress:", value: `${progress}/${count}` },
{ name: "Individual Levels Progress:", value: `${progress2}/${count2}` }
]);
await interaction.editReply({ embeds: [embed] });
let playerList = [];
// Iterates through each category
Expand Down Expand Up @@ -231,13 +233,15 @@ module.exports = {
}
// Update embed if enough progress has been made
if(Math.floor(progress/10) > lastEmbed) {
embed = new MessageEmbed()
.setColor("118855")
embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Leaderboard for " + game + ":")
.setThumbnail(data.assets["cover-large"].uri)
.setFooter({ text: date })
.addField("Full Game Progress:", `${progress}/${count}`)
.addField("Individual Levels Progress:", `${progress2}/${count2}`);
.addFields([
{ name: "Full Game Progress:", value: `${progress}/${count}` },
{ name: "Individual Levels Progress:", value: `${progress2}/${count2}` }
]);
await interaction.editReply({ embeds: [embed] });
lastEmbed = Math.floor(progress/10);
}
Expand Down Expand Up @@ -325,13 +329,15 @@ module.exports = {
}
// Update embed if enough progress has been made
if(Math.floor(progress2/10) > lastEmbed) {
embed = new MessageEmbed()
.setColor("118855")
embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Leaderboard for " + game + ":")
.setThumbnail(data.assets["cover-large"].uri)
.setFooter({ text: date })
.addField("Full Game Progress:", `${progress}/${count}`)
.addField("Individual Levels Progress:", `${progress2}/${count2}`);
.addFields([
{ name: "Full Game Progress:", value: `${progress}/${count}` },
{ name: "Individual Levels Progress:", value: `${progress2}/${count2}` }
]);
await interaction.editReply({ embeds: [embed] });
lastEmbed = Math.floor(progress2/10);
}
Expand All @@ -345,24 +351,20 @@ module.exports = {
playerList = playerList.filter(word => word[0].toLowerCase() !== "n/a");
// Which place to display
let place = 1;
let iterator = 0;
let countPlayer = 0;
embed = new MessageEmbed()
.setColor("118855")
embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Leaderboard for " + game + ":")
.setThumbnail(data.assets["cover-large"].uri)
.setFooter({ text: date });
for(const player of playerList) {
embed.addField("#" + place + " " + player[0].replace(/[\\*_~]/g, "\\$&"), `WRs:${player[1]}`, true);
countPlayer++;
for(let i = 0; i < 25; i++) {
const player = playerList[i];
embed.addFields([
{ name: "#" + place + " " + player[0].replace(/[\\*_~]/g, "\\$&"), value: `WRs:${player[1]}`, inline: true }
]);
// Increment only if next WR count is not equal to this count
if(playerList[iterator + 1] && playerList[iterator + 1][1] != playerList[iterator][1]) {
if(playerList[i + 1] && playerList[i + 1][1] != playerList[i][1]) {
place++;
}
if(countPlayer > 30) {
break;
}
iterator++;
}
await interaction.editReply({ embeds: [embed] });
},
Expand Down
6 changes: 3 additions & 3 deletions commands/link.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

Expand Down Expand Up @@ -27,8 +27,8 @@ module.exports = {
return await interaction.editReply(`No results found for **${game}**.`);
}
// Embed to return
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setTitle(answer.names.international)
.setURL(answer.weblink)
.setThumbnail(answer.assets["cover-large"].uri);
Expand Down
6 changes: 3 additions & 3 deletions commands/ping.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");

/**
Expand All @@ -12,8 +12,8 @@ module.exports = {
.setName("ping")
.setDescription("Provides bot response time."),
async execute(interaction) {
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setThumbnail("https://www.speedrun.com/images/1st.png")
.setTitle(`Ping: ${Date.now() - interaction.createdTimestamp}ms`);
await interaction.editReply({ embeds: [embed] });
Expand Down
10 changes: 6 additions & 4 deletions commands/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

Expand Down Expand Up @@ -43,12 +43,14 @@ module.exports = {
answer[i][0] = data[i].names.international;
answer[i][1] = data[i].abbreviation + "\n" + data[i].weblink;
}
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Results (Count: " + answer.length + ", Page: " + page + ")")
.setThumbnail("https://www.speedrun.com/images/1st.png");
answer.forEach(entry => {
embed.addField(entry[0], entry[1]);
embed.addFields([
{name: entry[0], value: entry[1] }
]);
});
if (answer.length == 20) {
embed.setFooter({ text: "There may be more pages. Use /search <game> <page>" });
Expand Down
16 changes: 10 additions & 6 deletions commands/unverified.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

Expand Down Expand Up @@ -33,15 +33,19 @@ module.exports = {
data = await tokens.fetch(`https://www.speedrun.com/api/v1/runs?game=${id}&status=new&max=200&orderby=submitted&direction=asc&offset=${data.pagination.offset + 200}`);
}
const num = data.pagination.offset + data.pagination.size;
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Result for: " + game)
.setThumbnail(gameData.data.assets["cover-large"].uri);
if(firstPage) {
embed.addField("Number of unverified runs: ", String(num))
.addField("Oldest unverified run: ", firstPage.submitted.substring(0,10));
embed.addFields([
{ name: "Number of unverified runs: ", value: String(num) },
{ name: "Oldest unverified run: ", value: firstPage.submitted.substring(0,10) }
]);
} else {
embed.addField("Number of unverified runs: ", String(num));
embed.addFields([
{name: "Number of unverified runs: ", value: String(num) }
]);
}
await interaction.editReply({ embeds: [embed] });
},
Expand Down
10 changes: 6 additions & 4 deletions commands/verified.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageEmbed } = require("discord.js");
const { EmbedBuilder } = require("discord.js");
const { SlashCommandBuilder } = require("@discordjs/builders");
const tokens = require("../index.js");

Expand Down Expand Up @@ -35,10 +35,12 @@ module.exports = {
// Number of runs = the total offset + the current size
const num = data.pagination.offset + data.pagination.size;
// Creates embed
const embed = new MessageEmbed()
.setColor("118855")
const embed = new EmbedBuilder()
.setColor("#118855")
.setTitle("Result for: " + user)
.addField("Number of runs verified: ", num >= 10000 ? ">= 10k" : String(num))
.addFields([
{name: "Number of runs verified: ", value: num >= 10000 ? ">= 10k" : String(num) }
])
.setThumbnail(playerData.data.assets.image.uri);
return await interaction.editReply({ embeds: [embed] });
},
Expand Down
Loading

0 comments on commit 3b09567

Please sign in to comment.