add racetime command

This commit is contained in:
2025-10-27 16:39:23 +01:00
parent 0b4f88803b
commit add96d7a2f
2 changed files with 33 additions and 0 deletions

View File

@@ -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

32
src/commands/racetime.ts Normal file
View File

@@ -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);
};
}
});