mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-18 16:51:38 +01:00
add racetime command
This commit is contained in:
@@ -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
32
src/commands/racetime.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user