From eb1f2eaf9042f7df4e2ed8cfdfe71bcfe8bf397a Mon Sep 17 00:00:00 2001 From: Andrew R Date: Sun, 21 Jun 2026 21:49:27 +0930 Subject: [PATCH 1/2] fix(tasks.check_whitelabel): fix task issues --- tasks/check_whitelabel.py | 54 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/tasks/check_whitelabel.py b/tasks/check_whitelabel.py index 2def9e0..1d2f358 100644 --- a/tasks/check_whitelabel.py +++ b/tasks/check_whitelabel.py @@ -10,26 +10,36 @@ async def check_whitelabel(bot: Bot): async for item in bot.whitelabel.db.find({}): try: - guild = await bot.fetch_guild(int(item["GuildID"])) # looking at the db, guild ids aren't always ints - except: - return - try: - owner = await guild.fetch_member(int(item["DiscordID"])) - except: - return - bot_member = guild.me - time = datetime.datetime.now(tz=datetime.UTC) - expiry = datetime.datetime.fromtimestamp(item["Expiry"]) - if expiry > time: - await owner.send(embed=discord.Embed( - title="Whitelabel Subscription Expired", - description="Your whitelabel subscription has expired, therefore, the avatar, banner, and bio will be reset. Please renew your subscription through the web dashboard or open a ticket if you need assistance." - )) - await bot_member.edit(avatar=None, banner=None, bio=None, reason="Whitelabel subscription expired") - return - - session = aiohttp.ClientSession() - av = await (await session.post(item["UserData"]["AvatarURL"])).read() - banner = await (await session.post(item["UserData"]["BannerURL"])).read() - await bot_member.edit(avatar=av, banner=banner, bio=item["UserData"]["Bio"]) + print(item) + if item["GuildID"] == 0: + await bot.whitelabel.delete(item["_id"]) + continue + try: + guild = await bot.fetch_guild(int(item["GuildID"])) # looking at the db, guild ids aren't always ints + except: + return + try: + owner = await guild.fetch_member(int(item["DiscordID"])) + except: + return + bot_member = guild.me or guild.get_member(bot.user.id) or await guild.fetch_member(bot.user.id) + + print(bot_member) + time = datetime.datetime.now(tz=datetime.UTC) + expiry = datetime.datetime.fromtimestamp(item["Expiry"], tz=datetime.UTC) + if expiry < time: + await owner.send(embed=discord.Embed( + title="Whitelabel Subscription Expired", + description="Your whitelabel subscription has expired, therefore, the avatar, banner, and bio will be reset. Please renew your subscription through the web dashboard or open a ticket if you need assistance." + )) + await bot_member.edit(avatar=None, banner=None, bio=None, reason="Whitelabel subscription expired") + return + + session = aiohttp.ClientSession() + av = await (await session.get(item["UserData"]["AvatarURL"])).read() + banner = await (await session.get(item["UserData"]["BannerURL"])).read() + await bot_member.edit(avatar=av, banner=banner, bio=item["UserData"]["Bio"]) + except Exception as e: + print(str(e)) + continue From 38eeb8a3db6177ff671d4bfdf94bc9783e5aabf1 Mon Sep 17 00:00:00 2001 From: Andrew R Date: Sun, 21 Jun 2026 21:50:46 +0930 Subject: [PATCH 2/2] fix(iterate_prc_logs): fix a ratelimit issue caused by recursion --- tasks/iterate_prc_logs.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tasks/iterate_prc_logs.py b/tasks/iterate_prc_logs.py index 5e12ca9..7efd36b 100644 --- a/tasks/iterate_prc_logs.py +++ b/tasks/iterate_prc_logs.py @@ -45,10 +45,10 @@ count_aggregate = global_aggregate + [{"$count": "total"}] -@tasks.loop(minutes=7, reconnect=True) +@tasks.loop(minutes=5, reconnect=True) async def iterate_prc_logs(bot): try: - server_count_list = await (await bot.settings.db.aggregate(count_aggregate)).to_list(length=None) + server_count_list = [i async for i in await bot.settings.db.aggregate(count_aggregate)] server_count = server_count_list[0]["total"] if server_count_list else 0 logging.warning(f"[ITERATE] Starting iteration for {server_count} servers") @@ -197,6 +197,7 @@ async def unprimitive_guild_process(items, bot): await asyncio.gather(*subtasks, return_exceptions=True) await bot.log_tracker.save_guild(guild.id) + await flush_pending_unbans(bot, guild.id) async def process_guild(bot, items, semaphore): async with semaphore: @@ -208,7 +209,6 @@ async def process_guild(bot, items, semaphore): except Exception as e: logging.warning(f"error processing guild: {e}") - await iterate_prc_logs(bot) @@ -516,6 +516,25 @@ async def process_player_logs(bot, settings, guild_id, player_logs, last_timesta return embeds, latest_timestamp +async def flush_pending_unbans(bot, guild_id: int): + now = int(datetime.datetime.now(tz=pytz.UTC).timestamp()) + pending = bot.punishments.db.find({ + "Guild": guild_id, + "CheckExecuted": {"$exists": False}, + "UntilEpoch": {"$lt": now}, + "Type": "Temporary Ban", + "Epoch": {"$gt": 1709164800}, + }) + async for item in pending: + try: + await bot.prc_api.unban_user(guild_id, item["UserID"]) + item["CheckExecuted"] = True + await bot.punishments.update_by_id(item) + await asyncio.sleep(1) + except Exception: + break + + async def is_username_found(username: str, members: list[discord.Member]) -> bool: pattern = re.compile(re.escape(username), re.IGNORECASE) member_found = False