Last active
June 1, 2020 14:29
-
-
Save slashinfty/95a61ef909bb9e61576b94014d8bf954 to your computer and use it in GitHub Desktop.
Are you in a racetime.gg race? (node.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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