From 6ae27f8b7f395b1ff4acab43214619d54736a274 Mon Sep 17 00:00:00 2001 From: AnInternetTroll Date: Sun, 4 Apr 2021 14:48:42 +0200 Subject: Reformatting --- cogs/src.py | 19 +++++++++++++------ cogs/utils.py | 61 ++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/cogs/src.py b/cogs/src.py index 83e15a9..e9cc88b 100755 --- a/cogs/src.py +++ b/cogs/src.py @@ -129,15 +129,19 @@ async def pendingRuns(self, ctx): while True: temp_json = await temp.json() runs.extend(temp_json["data"]) - if "pagination" not in temp_json or temp_json["pagination"]["size"] < 200: + 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" - ], + { + item["rel"]: item["uri"] + for item in temp_json["pagination"]["links"] + }["next"], headers=head, ) - + for run in runs: _id = run["id"] duration = timedelta(seconds=run["times"]["realtime_t"]) @@ -379,6 +383,7 @@ 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( @@ -397,7 +402,8 @@ async def queueLength(self, ctx, game): hold = [] async with self.bot.session.get( - f"https://www.speedrun.com/api/v1/runs?game={gameID}&status=new&max=200", headers=head + f"https://www.speedrun.com/api/v1/runs?game={gameID}&status=new&max=200", + headers=head, ) as temp: while True: if temp.status != 200: @@ -416,6 +422,7 @@ async def queueLength(self, ctx, game): await ctx.send(f"The queue for {gameName} has {len(hold)} runs") + class Src(commands.Cog): def __init__(self, bot): self.bot = bot diff --git a/cogs/utils.py b/cogs/utils.py index 1ad303d..ed43b7c 100755 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -119,7 +119,8 @@ class Utils(commands.Cog): rigged_findseed = { 280428276810383370: 12, # Thomas's User ID 199070670221475842: -1, # Kai's User ID - 615658069132836865: -12, # What a fraud! They didn't use their real name. + # What a fraud! They didn't use their real name. + 615658069132836865: -12, } if ctx.author.id in rigged_findseed: @@ -517,29 +518,34 @@ class Utils(commands.Cog): f"{discord.utils.escape_mentions(ctx.message.author.display_name)} your timezone has been set to {timeZone}" ) - @commands.cooldown(2, 60, commands.BucketType.guild) - @commands.command() - async def fboard(self, ctx, requested: str = "streak"): - """Show fair leaderboard (day or streak).""" - # get fair object - with open("fair.json", "r") as f: - fair = json.load(f) - - #Detect people who didn't maintain their streak. + @commands.cooldown(2, 60, commands.BucketType.guild) + @commands.command() + async def fboard(self, ctx, requested: str = "streak"): + """Show fair leaderboard (day or streak).""" + # get fair object + with open("fair.json", "r") as f: + fair = json.load(f) + + # Detect people who didn't maintain their streak. for user in fair: - tz = fair[user]["timezone"] - currentdate = datetime.datetime.now(timezone(tz)).date() - if fair[user]["date"] != str(currentdate) and fair[user]["date"] != str(currentdate-timedelta(1)): + tz = fair[user]["timezone"] + currentdate = datetime.datetime.now(timezone(tz)).date() + if fair[user]["date"] != str(currentdate) and fair[user]["date"] != str( + currentdate - timedelta(1) + ): fair[user]["streak"] = 1 - fair[user]["date"] = str(currentdate) - await ctx.send(self.bot.get_user(int(user)).mention + ": You lost your streak! <:sad:716629485449117708>") + fair[user]["date"] = str(currentdate) + await ctx.send( + self.bot.get_user(int(user)).mention + + ": You lost your streak! <:sad:716629485449117708>" + ) with open("fair.json", "w") as f: json.dump(fair, f, indent=4) leaderboard = [] - - #String the requested info with its respective user and store it in our list + + # String the requested info with its respective user and store it in our list if requested.lower() == "day": for user in fair: leaderboard.append(str(fair[user]["day"]) + user) @@ -551,25 +557,28 @@ class Utils(commands.Cog): flag = "Streak" else: - await ctx.send("Request the leaderboard by \"day\" or \"streak\".") + await ctx.send('Request the leaderboard by "day" or "streak".') return - #Sort the "info + user" strings as ints. + # Sort the "info + user" strings as ints. leaderboard.sort(reverse=True, key=int) - text = "" - embed = discord.Embed(title="Fair Leaderboard", color=7853978, timestamp=ctx.message.created_at) - - #Get the top 10 entries and extract the info and user from each string + text = "" + embed = discord.Embed( + title="Fair Leaderboard", color=7853978, timestamp=ctx.message.created_at + ) + + # Get the top 10 entries and extract the info and user from each string for i in range(10): entry = leaderboard[i][:-18] userstr = leaderboard[i][-18:] text = text + f"{i+1}. {self.bot.get_user(int(userstr))}: {entry} \n" - embed.add_field(name=flag, value=discord.utils.escape_mentions(text), inline=False) - + embed.add_field( + name=flag, value=discord.utils.escape_mentions(text), inline=False + ) + await ctx.send(embed=embed) - @commands.cooldown(1, 60, commands.BucketType.member) @commands.command() -- cgit v1.2.3