Skip to content

Commit

Permalink
Reimplemented daily lb
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-NCSU committed Sep 22, 2021
1 parent e1b788f commit 96f200d
Show file tree
Hide file tree
Showing 3 changed files with 419 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fetch = require('node-fetch');
const { MongoClient } = require("mongodb");
var cron = require('node-cron');


// Creates a rate limiting queue
Expand Down Expand Up @@ -71,6 +72,16 @@ const rest = new REST({ version: '9' }).setToken(token);
}
})();
*/

const scheduledCommandFiles = fs.readdirSync('./scheduledcommands').filter(file => file.endsWith('.js'));

for (const file of scheduledCommandFiles) {
const command = require(`./scheduledcommands/${file}`);
cron.schedule(command.data.interval, () => {
command.execute(client);
});
}

// Sets bot activity and announces that bot is ready for use
client.once('ready', async () => {
client.user.setActivity('speedrun.com | /help', { type: 'WATCHING' })
Expand Down Expand Up @@ -125,7 +136,7 @@ exports.fetch = async function limitFetch(text) {
if(data.status != 420) {
return data;
}
sleep(2000);
await sleep(2000);
}
}

Expand Down
16 changes: 16 additions & 0 deletions scheduledcommands/checkRun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { MessageEmbed } = require('discord.js');
const token = require('../index.js');

module.exports = {
data: {
interval: "0 0 0 * * *"
},
async execute(client) {
const gameData = await token.fetch(`https://www.speedrun.com/api/v1/runs?game=m1z9l2d0&status=new`);
for(run of gameData.data) {
if(run.values["j845q35n"] == "rqv0z7wl" && !run.comment.includes("/replay")) {
client.channels.cache.get("728402518014689333").send(run.weblink);
}
}
},
};
Loading

0 comments on commit 96f200d

Please sign in to comment.