diff options
author | randomidiot13 <52841549+randomidiot13@users.noreply.github.com> | 2021-02-20 02:25:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-20 02:25:36 +0000 |
commit | 2b672d4a9914d813dc20a4dc940ae0c6c8b79501 (patch) | |
tree | 3f025d5f7fdfa02cee08fff2c9d7f2475e028a70 | |
parent | 3f732efbcd7b2fb9bc6e595aee6347195bb1b143 (diff) | |
download | steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar.gz steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar.bz2 steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar.lz steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar.xz steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.tar.zst steve-bot-2b672d4a9914d813dc20a4dc940ae0c6c8b79501.zip |
Add verified command
If I did everything right, there should be a "verified" command that does the same thing as "src!v", roughly. Be advised that I have no idea if what I'm doing is correct, good, and/or functional.
-rwxr-xr-x | cogs/src.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cogs/src.py b/cogs/src.py index 8419efb..72ec722 100755 --- a/cogs/src.py +++ b/cogs/src.py @@ -331,6 +331,43 @@ async def verifyNew(self, apiKey=None, userID=None): else: await member.remove_roles(RunneRole) +async def verifiedCount(self, ctx, modName): + head = { + "Accept": "application/json", + "User-Agent": "mcbeDiscordBot/1.0" + } + + r = requests.get( + f"https://www.speedrun.com/api/v1/users/{modName}", + headers=head + ) + if r.status_code != 200: + await ctx.send(f"Could not find user {modName}") + return + try: + modID = r.json()['data']['id'] + except: + await ctx.send("Something went wrong") + return + + hold = [] + temp = requests.get( + f"https://www.speedrun.com/api/v1/runs?examiner={modID}&max=200", + headers=head) + while True: + if temp.status_code != 200: + await ctx.send("Something went wrong") + return + temp_json = temp.json() + hold.extend(temp_json['data']) + if 'pagination' not in temp_json or temp_json['pagination']['size'] < 200: + break + temp = requests.get( + {item['rel']: item['uri'] + for item in temp_json['pagination']['links']}['next'], + headers=head) + + await ctx.send(f"{modName} has verified {len(hold)} runs") class Src(commands.Cog): def __init__(self, bot): @@ -401,6 +438,14 @@ class Src(commands.Cog): userID = ctx.message.author.id await verifyNew(self, apiKey, userID) + @commands.command() + async def verified(self, ctx, modName=None): + async with ctx.typing(): + if modName is None: + await ctx.send("Please supply a moderator to view stats of") + return + await verifiedCount(self, ctx, modName) + @tasks.loop(minutes=10.0) async def checker(self): data = json.loads(Path("./api_keys.json").read_text()) |