Skip to content

Commit

Permalink
Removed api
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Sep 9, 2021
1 parent 1766ea3 commit f44bc22
Show file tree
Hide file tree
Showing 22 changed files with 53 additions and 182 deletions.
14 changes: 3 additions & 11 deletions Limiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Limit {
let self = this;
// Repeats checking until there are enough points
(function wait() {
if(self.getPoints() - num >= 0) { // If there is room to remove the points
self.setPoints(self.getPoints() - num); // Remove the points
setTimeout(() => self.addPoints(num), 65000); // Add the points back 65 seconds after
if(self.points - num >= 0) { // If there is room to remove the points
self.points = self.points - num; // Remove the points
setTimeout(() => self.addPoints(num), 70000); // Add the points back 65 seconds after
return resolve();
} else {
setTimeout(wait, 1000); // Else try again after 1 second
Expand All @@ -86,13 +86,5 @@ class Limit {
}
return this.points;
}

/**
* Alias for removePoints(num)
* @param {*} num number of points to remove
*/
removeTokens(num) {
return this.removePoints(num);
}
}
module.exports = Limit;
9 changes: 0 additions & 9 deletions api/categories.js

This file was deleted.

9 changes: 0 additions & 9 deletions api/examine.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/game-sub.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/game.js

This file was deleted.

13 changes: 0 additions & 13 deletions api/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/leaderboard.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/link.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/new.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/player.js

This file was deleted.

9 changes: 0 additions & 9 deletions api/search.js

This file was deleted.

22 changes: 0 additions & 22 deletions api/time.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/user.js

This file was deleted.

8 changes: 0 additions & 8 deletions api/variables.js

This file was deleted.

20 changes: 0 additions & 20 deletions api/wr.js

This file was deleted.

13 changes: 10 additions & 3 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 commands = require('../api');
const tokens = require('../index.js')

/**
* Function to provide a list of categories for the given game
Expand All @@ -18,7 +18,7 @@ module.exports = {
),
async execute(interaction) {
const game = interaction.options.get('game').value.toLowerCase();
const { data } = await commands.Categories.getCategories(game);
const { data } = await tokens.fetch(`https://www.speedrun.com/api/v1/games?abbreviation=${game}&embed=categories.variables`);
// Checks if game exists
if (!data.length) {
return await interaction.editReply(`No results found for **${game}**.`);
Expand All @@ -30,6 +30,7 @@ module.exports = {
.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) {
let variables = '';
if (category.variables.data[0]) {
Expand All @@ -42,7 +43,13 @@ module.exports = {
} else {
variables = 'None';
}
embed.addField('**Category:** ' + category.name + '** - id:** ' + category.id, ' **Variables:** ' + variables + '\n');
const string = '**Category:** ' + category.name + '** - id:** ' + category.id
const string2 = ' **Variables:** ' + variables + '\n';
size += string.length + string2.length;
if(size > 6000) {
break;
}
embed.addField(string, string2);
}
return await interaction.editReply({ embeds: [embed] });
},
Expand Down
12 changes: 5 additions & 7 deletions commands/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const commands = require('../api');
const tokens = require('../index.js');
const fetch = require('node-fetch');
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');

Expand All @@ -21,7 +19,7 @@ module.exports = {
const game = interaction.options.get('game').value.toLowerCase();

// Retrieves all subcategories for the full game and ILs
const {data} = await commands.NewLB.getSubcategories(game);
const {data} = await tokens.fetch(`https://www.speedrun.com/api/v1/games/${game}?embed=categories.variables,levels.variables`);
// If nothing is returned
if (!data) {
return await interaction.editReply(`No results found for **${game}**.`);
Expand Down Expand Up @@ -123,7 +121,7 @@ module.exports = {
let data2;
// If category has no sub categories
if(c[2].length == 0) {
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()));
data2 = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?top=1&embed=players`);
for(const run of data2.data.runs) {
b:
for(const player of run.run.players) {
Expand Down Expand Up @@ -157,7 +155,7 @@ module.exports = {
} else {
varString += `&var-${c[1][0]}=${o}`;
}
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()));
data2 = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${c[0]}?` + varString.substr(1) + '&top=1&embed=players');
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(data2);
Expand Down Expand Up @@ -204,7 +202,7 @@ module.exports = {
for(const c of sublevels) {
let data3;
if(c[1][2].length == 0) {
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()));
data3 = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?top=1&embed=players`);
for(const run of data3.data.runs) {
b:
for(const player of run.run.players) {
Expand Down Expand Up @@ -238,7 +236,7 @@ module.exports = {
} else {
varString += `&var-${c[1][1][0]}=${o}`;
}
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()));
data3 = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/level/${c[0]}/${c[1][0]}?` + varString.substr(1) + '&top=1&embed=players');
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(data3);
Expand Down
4 changes: 2 additions & 2 deletions commands/link.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const commands = require('../api');
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const tokens = require('../index.js')

/**
* Function to provide a link to the given game
Expand All @@ -16,7 +16,7 @@ module.exports = {
),
async execute(interaction) {
const game = interaction.options.get('game').value.toLowerCase();
const {data} = await commands.Link.getLink(game);
const {data} = await tokens.fetch(`https://www.speedrun.com/api/v1/games?abbreviation=${game}`);
[answer] = data;
// Checks if game exists
if (!answer || answer.length == 0) {
Expand Down
5 changes: 3 additions & 2 deletions commands/search.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const commands = require('../api');
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const tokens = require('../index.js')

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -23,7 +23,8 @@ module.exports = {
} else {
page = page.value;
}
const { data } = await commands.Search.getSearch(search, page);
let offset = (page - 1) * 20;
const { data } = await tokens.fetch(`https://www.speedrun.com/api/v1/games?name=${search}&offset=${offset}`);
if (!data.length) {
return interaction.editReply(`No results found for **${search}**.`)
}
Expand Down
8 changes: 4 additions & 4 deletions commands/unverified.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const commands = require('../api');
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const tokens = require('../index.js')

/**
* Function to provide a link to the given game
Expand All @@ -16,15 +16,15 @@ module.exports = {
),
async execute(interaction) {
const game = interaction.options.get('game').value.toLowerCase();
const gameData = await commands.Game.getGame(game);
const gameData = await tokens.fetch(`https://www.speedrun.com/api/v1/games/${game}`);
if(!gameData.data) {
return await interaction.editReply('Game does not exist.');
}
const id = gameData.data.id;
let data = await commands.New.getUnexamine(id);
let data = await tokens.fetch(`https://www.speedrun.com/api/v1/runs?game=${id}&status=new&max=200&orderby=submitted&direction=asc`);
const firstPage = data.data[0];
while (data.pagination.size == 200){
data = await commands.New.getUnexamine(id, data.pagination.offset + 200);
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()
Expand Down
12 changes: 6 additions & 6 deletions commands/verified.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const commands = require('../api');
const { MessageEmbed } = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const tokens = require('../index.js')

/**
* Returns the number of runs verified by the user
Expand All @@ -17,20 +17,20 @@ module.exports = {
async execute(interaction) {
const user = interaction.options.get('user').value.toLowerCase();
//Search for user on speedrun.com
const playerData = await commands.User.getUser(user);
const playerData = await tokens.fetch(`https://www.speedrun.com/api/v1/users/${user}`);
//If player doesn't exist
if(!playerData.data) {
return await interaction.editReply('User does not exist.');
}
//Retrieve runs for game
const id = playerData.data.id;
let data = await commands.Examine.getExamine(id);
let data = await tokens.fetch(`https://www.speedrun.com/api/v1/runs?examiner=${id}&max=200`);
//While the pagination.size == 200 keep looping
while (data.size == 200 && data.offset != 9800){
data = await commands.Examine.getExamine(id, data.offset + 200);
while (data.pagination.size == 200 && data.pagination.offset != 9800){
data = await tokens.fetch(`https://www.speedrun.com/api/v1/runs?examiner=${id}&max=200&offset=${data.pagination.offset + 200}`);
}
//Number of runs = the total offset + the current size
const num = data.offset + data.size;
const num = data.pagination.offset + data.pagination.size;
//Creates embed
const embed = new MessageEmbed()
.setColor('118855')
Expand Down
Loading

0 comments on commit f44bc22

Please sign in to comment.