Skip to content

Instantly share code, notes, and snippets.

@slashinfty
Last active June 1, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashinfty/95a61ef909bb9e61576b94014d8bf954 to your computer and use it in GitHub Desktop.
Save slashinfty/95a61ef909bb9e61576b94014d8bf954 to your computer and use it in GitHub Desktop.
Are you in a racetime.gg race? (node.js)
const fetch = require('node-fetch');
module.exports = {
getLink: async function(client, channel) {
const siteRoot = 'https://racetime.gg';
const raceSearch = await fetch(`${siteRoot}/races/data`);
const races = await raceSearch.json();
if (races.races.length === 0) client.say(channel, 'No active races');
else {
let foundRace = null;
races.races.forEach(async (race) => {
const raceUrl = race.data_url;
const lookupSearch = await fetch(`${siteRoot}${raceUrl}`);
const lookup = await lookupSearch.json();
for (let i = 0; i < lookup.entrants.length; i++) {
if (lookup.entrants[i].user.name === "dad infinitum") { //your racetime.gg name here
foundRace = lookup.data_url;
break;
}
}
});
if (foundRace === null) client.say(channel, 'dad infinitum is not in any races'); //change for your name
else {
const game = foundRace.category.name + ' - ' + foundRace.goal.name; //displays like "Game - Category"
const link = 'https://racetime.gg' + foundRace.url + '/spectate';
client.say(channel, 'Currently racing ' + game + ' - watch at ' + link);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment