diff options
author | Thomas Voss <57815710+Mango0x45@users.noreply.github.com> | 2021-03-21 00:13:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-21 00:13:45 +0000 |
commit | 335eb48bf41ceb2ea3732aee936fac73d9fe7742 (patch) | |
tree | 2e85723413d3447ccfe36eedaf64c9f3575a3a8a /cogs/src.py | |
parent | b2d6117e8955e26d3faaed4fbee8d4b0b702c875 (diff) | |
parent | 8ace61d6fc154579186bc2a8df67aef96fea3d3b (diff) | |
download | steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar.gz steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar.bz2 steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar.lz steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar.xz steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.tar.zst steve-bot-335eb48bf41ceb2ea3732aee936fac73d9fe7742.zip |
Merge pull request #49 from randomidiot13/patch-2
Diffstat (limited to 'cogs/src.py')
-rwxr-xr-x | cogs/src.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cogs/src.py b/cogs/src.py index 7dde708..9ddfbfb 100755 --- a/cogs/src.py +++ b/cogs/src.py @@ -379,6 +379,42 @@ async def verifiedCount(self, ctx, modName): await ctx.send(f"{modName} has verified {len(hold)} runs") +async def queueLength(self, ctx, game): + head = {"Accept": "application/json", "User-Agent": "mcbeDiscordBot/1.0"} + async with self.bot.session.get( + f"https://www.speedrun.com/api/v1/games/{game}", headers=head + ) as r: + if r.status != 200: + await ctx.send(f"Could not find game {game}") + return + try: + r_json = await r.json() + gameID = r_json["data"]["id"] + gameName = r_json["data"]["names"]["international"] + except: + await ctx.send("Something went wrong") + return + + hold = [] + async with self.bot.session.get( + f"https://www.speedrun.com/api/v1/runs?game={gameID}&max=200", headers=head + ) as temp: + while True: + if temp.status != 200: + await ctx.send("Something went wrong") + return + temp_json = await temp.json() + hold.extend(temp_json["data"]) + if "pagination" not in temp_json or temp_json["pagination"]["size"] < 200: + break + temp = await self.bot.session.get( + {item["rel"]: item["uri"] for item in temp_json["pagination"]["links"]}[ + "next" + ], + headers=head, + ) + + await ctx.send(f"The queue for {gameName} has {len(hold)} runs") class Src(commands.Cog): def __init__(self, bot): @@ -457,6 +493,14 @@ class Src(commands.Cog): return await verifiedCount(self, ctx, modName) + @commands.command() + async def queue(self, ctx, game=None): + async with ctx.typing(): + if game is None: + await ctx.send("Please supply a game to get the queue length of") + return + await queueLength(self, ctx, game) + @tasks.loop(minutes=10.0) async def checker(self): data = json.loads(Path("./api_keys.json").read_text()) |