Skip to content

Commit

Permalink
Change infinite loop to max at 20 retries
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Oct 16, 2022
1 parent a030934 commit 15fd97f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
{
"args": "none"
}
],
"no-constant-condition": [
"error",
{
"checkLoops": false
}
]
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ Finds runners with verified runs of certain categories and automatically submits
### Invalid Check
Ensures runs submitted to categories managed by a bot are rejected.

### Old Run Check
Checks a list of games for unverified runs older than 2 weeks. Sends a list of "old runs" to logging channel.

## Credits
* [Nick-NCSU](https://github.com/Nick-NCSU) Developer
2 changes: 1 addition & 1 deletion ScheduledCommands/checkInvalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
async execute(client) {
const channel = await client.channels.cache.get("1022357372854870076");
let data = await tokens.fetch(`https://www.speedrun.com/api/v1/runs?status=new&category=zd3q41ek&max=${Math.floor(Math.random() * 10 + 10)}`);
const blacklistedOptions = new Set(["5q8yjpkl", "0q50vd21"])
const blacklistedOptions = new Set(["5q8yjpkl", "0q50vd21"]);
for(const run of data.data.filter((run) => blacklistedOptions.has(run.values?.yn2m5ye8))) {
const status = {
"status": {
Expand Down
4 changes: 2 additions & 2 deletions ScheduledCommands/combinedLB.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let players = [];

async function findPlayers(game, category, vars, mode) {
const varMap = Object.entries(vars);
const varString = varMap.length ? `?${varMap.map(([variable, option]) => `var-${variable}=${option}`).join('&')}` : '';
const varString = varMap.length ? `?${varMap.map(([variable, option]) => `var-${variable}=${option}`).join("&")}` : "";
const data = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${category}${varString}`);
// Iterates through the runs in the category
for (const run of data.data.runs) {
Expand Down Expand Up @@ -80,7 +80,7 @@ async function updateRuns(game, category, vars, client) {
await channel.send({ embeds: [embed] });

const varMap = Object.entries(vars);
const varString = varMap.length ? `?${varMap.map(([variable, option]) => `var-${variable}=${option}`).join('&')}` : '';
const varString = varMap.length ? `?${varMap.map(([variable, option]) => `var-${variable}=${option}`).join("&")}` : "";

const data = await tokens.fetch(`https://www.speedrun.com/api/v1/leaderboards/${game}/category/${category}${varString}`);
// Filters out only the players with a time in every category
Expand Down
2 changes: 1 addition & 1 deletion ScheduledCommands/oldRunCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function checkRuns(game, client) {
return {
name: run.weblink,
value: new Date(run.submitted).toISOString().slice(0, 10)
}
};
}));
await channel.send({ embeds: [embed] });
}
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ exports.limit = function getLimit() {

exports.fetch = async function limitFetch(text) {
let data;
while(true) {
let attemptCount = 0;
while(attemptCount++ < 20) {
await limiter.removePoints(1).then(data = await fetch(text).then(response => response.json()));
if(data.status != 420) {
return data;
Expand All @@ -162,7 +163,8 @@ exports.fetch = async function limitFetch(text) {

exports.post = async function limitPost(text, params) {
let data;
while(true) {
let attemptCount = 0;
while(attemptCount++ < 20) {
await limiter.removePoints(1).then(data = await fetch(text, params).then(response => response.json()));
if(data.status != 420) {
return data;
Expand Down

0 comments on commit 15fd97f

Please sign in to comment.