Skip to content

Commit

Permalink
Fixed images/assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Aug 23, 2021
1 parent f8dda0e commit 0a10b40
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 51 deletions.
2 changes: 1 addition & 1 deletion commands/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
.setColor('118855')
.setTitle(dataArr.names.international)
.setURL(dataArr.weblink)
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(dataArr.assets["cover-large"].uri)
// Iterates through all the categories for the game
for (const category of dataArr.categories.data) {
let variables = '';
Expand Down
59 changes: 43 additions & 16 deletions commands/dream.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
const { MessageEmbed } = require('discord.js');
const { now } = require('perf_hooks').performance;
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
data: new SlashCommandBuilder().setName('dream').setDescription('Simulates Dream\'s pearl and blaze rod odds.'),
data: new SlashCommandBuilder()
.setName('dream')
.setDescription('Simulates Dream\'s pearl and blaze rod odds.')
.addIntegerOption(option =>
option.setName('simulations')
.setDescription('Number of simulations to run (Max 1,000,000')
.setRequired(true)
),
async execute(interaction) {
const time1 = now();
let num = 0;
for(let i = 0; i < 263; i++) {
if(Math.random() <= (20/423)) {
num++;
}
let sim = interaction.options.get('simulations');
if(!sim) {
sim = 1;
} else {
sim = sim.value;
}
if(sim > 1000000) {
return await interaction.editReply('Too many simulations (' + sim + ')');
}
let num2 = 0;
for(let i = 0; i < 306; i++) {
if(Math.random() * 100 <= 50) {
num2++;
let pMax = 0;
let rMax = 0;
let pTotal = 0;
let rTotal = 0;
for(let count = 0; count < sim; count++) {
let pCount = 0;
for(let i = 0; i < 263; i++) {
if(Math.random() <= (20/423)) {
pCount++;
}
}
let rCount = 0;
for(let i = 0; i < 306; i++) {
if(Math.random() * 100 <= 50) {
rCount++;
}
}
pMax = Math.max(pMax, pCount);
rMax = Math.max(rMax, rCount);
pTotal += pCount;
rTotal += rCount;
}
const difference = num >= 42 ? '+' + num - 42 : num - 42;
const difference2 = num2 >= 211 ? '+' + num2 - 211 : num2 - 211;
const difference = pMax >= 42 ? '+' + pMax - 42 : pMax - 42;
const difference2 = rMax >= 211 ? '+' + rMax - 211 : rMax - 211;
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Your Results:')
.addField('Number of pearl trades: ' + num + '/262', 'Number of pearl trades (Dream): 42/262')
.addField('Number of rods: ' + num2 + '/305', 'Number of rods (Dream): 211/305')
.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)
await interaction.editReply({ embeds: [embed] });
},
Expand Down
2 changes: 1 addition & 1 deletion commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Help')
.setThumbnail('https://www.speedrun.com/themes/Default/1st.png')
.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.')
Expand Down
44 changes: 22 additions & 22 deletions commands/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ module.exports = {
let embed = new MessageEmbed()
.setColor('118855')
.setTitle('Leaderboard for ' + game + ':')
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(data.assets["cover-large"].uri)
.setFooter(date)
.addField('Full Game Progress:', `${progress}/${count}`)
.addField('Individual Levels Progress:', `${progress2}/${count2}`)
await interaction.editReply({ embeds: [embed] });
let playerList = [];

for(const c of subcategories) {
let data;
let data2;
// If category has no sub categories
if(c[2].length == 0) {
await tokens.limit().removeTokens(1).then(data = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?top=1&embed=players`).then(response => response.json()));
for(const run of data.data.runs) {
await tokens.limit().removeTokens(1).then(data2 = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?top=1&embed=players`).then(response => response.json()));
for(const run of data2.data.runs) {
b:
for(const player of run.run.players) {
for(const item of playerList) {
Expand All @@ -134,7 +134,7 @@ module.exports = {
}
}
if(player.rel == "user") {
for(const user of data.data.players.data) {
for(const user of data2.data.players.data) {
if(player.id == user.id) {
playerList.push([user.names.international, 1, user.id]);
continue b;
Expand All @@ -157,13 +157,13 @@ module.exports = {
} else {
varString += `&var-${c[1][0]}=${o}`;
}
await tokens.limit().removeTokens(1).then(data = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?` + varString.substr(1) + '&top=1&embed=players').then(response => response.json()));
if(!data.data) {
await tokens.limit().removeTokens(1).then(data2 = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?` + varString.substr(1) + '&top=1&embed=players').then(response => response.json()));
if(!data2.data) {
console.log(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?` + varString.substr(1) + '&top=1&embed=players');
console.log(data);
console.log(data2);
continue;
}
for(const run of data.data.runs) {
for(const run of data2.data.runs) {
b:
for(const player of run.run.players) {
for(const item of playerList) {
Expand All @@ -173,7 +173,7 @@ module.exports = {
}
}
if(player.rel == "user") {
for(const user of data.data.players.data) {
for(const user of data2.data.players.data) {
if(player.id == user.id) {
playerList.push([user.names.international, 1, user.id]);
continue b;
Expand All @@ -192,7 +192,7 @@ module.exports = {
embed = new MessageEmbed()
.setColor('118855')
.setTitle('Leaderboard for ' + game + ':')
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(data.assets["cover-large"].uri)
.setFooter(date)
.addField('Full Game Progress:', `${progress}/${count}`)
.addField('Individual Levels Progress:', `${progress2}/${count2}`)
Expand All @@ -202,10 +202,10 @@ module.exports = {
}

for(const c of sublevels) {
let data;
let data3;
if(c[1][2].length == 0) {
await tokens.limit().removeTokens(1).then(data = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?top=1&embed=players`).then(response => response.json()));
for(const run of data.data.runs) {
await tokens.limit().removeTokens(1).then(data3 = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?top=1&embed=players`).then(response => response.json()));
for(const run of data3.data.runs) {
b:
for(const player of run.run.players) {
for(const item of playerList) {
Expand All @@ -215,7 +215,7 @@ module.exports = {
}
}
if(player.rel == "user") {
for(const user of data.data.players.data) {
for(const user of data3.data.players.data) {
if(player.id == user.id) {
playerList.push([user.names.international, 1, user.id]);
continue b;
Expand All @@ -238,13 +238,13 @@ module.exports = {
} else {
varString += `&var-${c[1][1][0]}=${o}`;
}
await tokens.limit().removeTokens(1).then(data = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?` + varString.substr(1) + '&top=1&embed=players').then(response => response.json()));
if(!data.data) {
await tokens.limit().removeTokens(1).then(data3 = await fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?` + varString.substr(1) + '&top=1&embed=players').then(response => response.json()));
if(!data3.data) {
console.log(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?` + varString.substr(1) + '&top=1&embed=players');
console.log(data);
console.log(data3);
continue;
}
for(const run of data.data.runs) {
for(const run of data3.data.runs) {
b:
for(const player of run.run.players) {
for(const item of playerList) {
Expand All @@ -254,7 +254,7 @@ module.exports = {
}
}
if(player.rel == "user") {
for(const user of data.data.players.data) {
for(const user of data3.data.players.data) {
if(player.id == user.id) {
playerList.push([user.names.international, 1, user.id]);
continue b;
Expand All @@ -273,7 +273,7 @@ module.exports = {
embed = new MessageEmbed()
.setColor('118855')
.setTitle('Leaderboard for ' + game + ':')
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(data.assets["cover-large"].uri)
.setFooter(date)
.addField('Full Game Progress:', `${progress}/${count}`)
.addField('Individual Levels Progress:', `${progress2}/${count2}`)
Expand All @@ -295,7 +295,7 @@ module.exports = {
embed = new MessageEmbed()
.setColor('118855')
.setTitle('Leaderboard for ' + game + ':')
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(data.assets["cover-large"].uri)
.setFooter(date)
for(const player of playerList) {
embed.addField('#' + place + ' ' + player[0].replace(/[*_~]/g, "\\$&"), `WRs:${player[1]}`, true)
Expand Down
2 changes: 1 addition & 1 deletion commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
.setColor('118855')
.setTitle(answer.names.international)
.setURL(answer.weblink)
.setThumbnail(`https://www.speedrun.com/themes/${game}/cover-256.png`)
.setThumbnail(answer.assets["cover-large"].uri)
await interaction.editReply({ embeds: [embed] });
},
};
2 changes: 1 addition & 1 deletion commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
async execute(interaction) {
const embed = new MessageEmbed()
.setColor('118855')
.setThumbnail('https://www.speedrun.com/themes/Default/1st.png')
.setThumbnail('https://www.speedrun.com/images/1st.png')
.setTitle(`Ping: ${Date.now() - interaction.createdTimestamp}ms`)
await interaction.editReply({ embeds: [embed] });
},
Expand Down
2 changes: 1 addition & 1 deletion commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Results (Count: ' + answer.length + ', Page: ' + page + ')')
.setThumbnail('https://www.speedrun.com/themes/Default/1st.png')
.setThumbnail('https://www.speedrun.com/images/1st.png')
answer.forEach(entry => {
embed.addField(entry[0], entry[1]);
});
Expand Down
9 changes: 4 additions & 5 deletions commands/unverified.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ module.exports = {
}
const num = data.pagination.offset + data.pagination.size;
const embed = new MessageEmbed()
.setColor('118855')
.setTitle('Result for: ' + game)
.setThumbnail(gameData.data.assets["cover-large"].uri)
if(firstPage) {
embed.setColor('118855')
embed.setTitle('Result for: ' + game)
embed.addField('Number of unverified runs: ', String(num))
embed.addField('Oldest unverified run: ', firstPage.submitted.substring(0,10))
.addField('Oldest unverified run: ', firstPage.submitted.substring(0,10))
} else {
embed.setColor('118855')
embed.setTitle('Result for: ' + game)
embed.addField('Number of unverified runs: ', String(num))
}
await interaction.editReply({ embeds: [embed] });
Expand Down
1 change: 1 addition & 0 deletions commands/verified.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = {
.setColor('118855')
.setTitle('Result for: ' + user)
.addField('Number of runs verified: ', num >= 10000 ? '>= 10k' : String(num))
.setThumbnail(playerData.data.assets.image.uri)
return await interaction.editReply({ embeds: [embed] });
},
};
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Client, Intents, Collection } = require('discord.js');
const fs = require('fs');
const Limit = require('./Limiter.js');
const Queue = require('queue-promise');
const limiter = new Limit(95);
const limiter = new Limit(49);
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');

Expand Down Expand Up @@ -43,8 +43,8 @@ const rest = new REST({ version: '9' }).setToken(token);
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands('728401850033897574'),
{ body: commands },
Routes.applicationGuildCommands("728401850033897574", "430074563703996417"),
{ body: [] },
);
console.log('Successfully reloaded application (/) commands.');
Expand Down

0 comments on commit 0a10b40

Please sign in to comment.