diff --git a/README.md b/README.md index 2b21923..42d7684 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ COMMAND|FUNCTION|USER|ALIASES|DISABLEABLE `alltimeleaderboard`|Get the K/D leaderboard of all time [(info)](#leaderboards)|anyone|`alltimeleaderboard` `alltimekdleaderboard`|:white_check_mark: `qbucksleaderboard`|Get the current qbucks leaderboard [(info)](#leaderboards)|anyone|`qbucksleaderboard` `moneyleaderboard` `baltop`|:white_check_mark: `anivtimeouts`|Get the amount of timeouts, dodges and dodge percentage from aniv timeouts [(info)](#aniv-timeouts)|anyone|`anivtimeouts` `anivtimeout`|:white_check_mark: +`racetime`|Get the racetime.gg room the streamer is currently in. Needs to have twitch linked to racetime account|anyone|`racetime` `raceroom`|:white_check_mark: ### Qweribucks/Item commands diff --git a/src/commands/racetime.ts b/src/commands/racetime.ts new file mode 100644 index 0000000..13baf6c --- /dev/null +++ b/src/commands/racetime.ts @@ -0,0 +1,32 @@ +import { Command, sendMessage } from "commands"; +import logger from "lib/logger"; +import { streamerId } from "main"; +import User from "user"; + +export default new Command({ + name: 'racetime', + aliases: ['racetime', 'raceroom'], + usertype: 'chatter', + execution: async msg => { + try { // this might be some of the worst http code ever + const streamer = await User.initUserId(streamerId); + + const races = await fetch(`https://racetime.gg/smr/data`).then(a => a.json() as any); + if (races.current_races.length < 1) { await sendMessage(`No Super Metroid Randomizer races active`, msg.messageId); return; }; + + for (const race of races.current_races) { + const data = await fetch(`https://racetime.gg${race.data_url}`).then(a => a.json() as any); + for (const racer of data.entrants) { + if (racer.twitch_name === streamer?.username) { + await sendMessage(`https://racetime.gg${data.url}`, msg.messageId); + return; + }; + }; + }; + await sendMessage('Streamer is not in a racetime race.', msg.messageId); + } catch (err) { + await sendMessage("Failed to get racetime status", msg.messageId); + logger.err(err as string); + }; + } +});