From 231b2c5ec69a37e16509929dfae494042ae11344 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Sun, 31 Mar 2024 00:48:24 -0500 Subject: [PATCH 1/5] fix: fixed invitations regex --- src/utils/calculation_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/calculation_utils.py b/src/utils/calculation_utils.py index f069682..e6a8377 100644 --- a/src/utils/calculation_utils.py +++ b/src/utils/calculation_utils.py @@ -206,10 +206,11 @@ async def is_valid_date(date: str): return False, None, None, None + async def extract_usernames(message: str): # Define regular expressions for both formats - format1_pattern = r"🎉 \*\*(?:\[(.*?)\] )?(.*?)\*\* joined the guild! \*\*They weren't invited by anyone\." - format2_pattern = r"🎉 \*\*(?:\[(.*?)\] )?(.*?)\*\* invited(?: \*\*\[(.*?)\] )?(?:\*\*)? (?:\*\*)?(.*?)\*\* to the guild!" + format1_pattern = r"🎉 \*\*(.*?)\*\* invited \*\*(.*?)\*\* to the guild!" + format2_pattern = r"🎉 \*\*(.*?)\*\* joined the guild! \*\*They weren't invited by anyone\." # Check if it matches format 1 match_format1 = re.match(format1_pattern, message) From 0bf5d9acd7d7282f6cd39e4e196dd096deb10ccb Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Sun, 31 Mar 2024 00:48:44 -0500 Subject: [PATCH 2/5] fix: changed code to work with updated regex --- src/utils/calculation_utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/utils/calculation_utils.py b/src/utils/calculation_utils.py index e6a8377..427674f 100644 --- a/src/utils/calculation_utils.py +++ b/src/utils/calculation_utils.py @@ -215,17 +215,15 @@ async def extract_usernames(message: str): # Check if it matches format 1 match_format1 = re.match(format1_pattern, message) if match_format1: - username1 = match_format1.group(2) - return username1, None + username1 = match_format1.group(1) + username2 = match_format1.group(2) + return username1, username2 # Check if it matches format 2 match_format2 = re.match(format2_pattern, message) if match_format2: - username1 = match_format2.group(2) - username2 = match_format2.group(4) - if username2.startswith('['): # Check if the second username starts with '[' indicating a rank - username2 = username2.split('] ')[1] # Remove the rank from the second username - return username1, username2.strip('**') # Remove any leading or trailing '**' + username1 = match_format2.group(1) + return username1, None # If it doesn't match any format, return None for both usernames return None, None From dd29b9babd3a92cff79d6769ba5dc8ede725d4b0 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Sun, 31 Mar 2024 00:49:01 -0500 Subject: [PATCH 3/5] fix: ,invites works without a username now --- src/cogs/guild.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/guild.py b/src/cogs/guild.py index 99471e7..104abfa 100644 --- a/src/cogs/guild.py +++ b/src/cogs/guild.py @@ -92,8 +92,8 @@ async def invites(self, ctx, name: str = None): """View your invitation stats""" await ctx.defer() if not name: - uuid, _ = await get_db_uuid_username_from_discord_id(ctx.author.id) - res = await String(string=uuid).invites() + uuid, username = await get_db_uuid_username_from_discord_id(ctx.author.id) + res = await String(uuid=uuid, username=username).invites() else: res = await String(string=name).invites() await ctx.respond(embed=res) From 674a3d574159d7c878b73394bfe5d47a9e106b34 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Sun, 31 Mar 2024 00:49:22 -0500 Subject: [PATCH 4/5] feat: added info to invites footer --- src/func/String.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/func/String.py b/src/func/String.py index 2045dac..4340c26 100644 --- a/src/func/String.py +++ b/src/func/String.py @@ -309,5 +309,7 @@ async def invites(self): embed.add_field(name="Total Invites", value=total_invites, inline=True) embed.add_field(name="Total Valid Invites", value=total_valid_invites, inline=True) embed.set_footer(text="Total invites and total valid invites do not include this week's invites. They are " - "updated at the end of the week.") + "updated at the end of the week.\nAn invite is considered valid if they earn " + f"2 * {format(member_req, ',d')} at the end of the week. " + "If they joined in the middle of the week, their guild experience will be scaled up.") return embed From 546b8ecce5760c36f62072728dade3481d0bb788 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Sun, 31 Mar 2024 00:49:33 -0500 Subject: [PATCH 5/5] refactor: improved readability --- src/func/String.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/func/String.py b/src/func/String.py index 4340c26..0967e92 100644 --- a/src/func/String.py +++ b/src/func/String.py @@ -16,7 +16,7 @@ months, neg_color, neutral_color, pos_color, qotd_ans_channel_id, qotd_channel_id, ticket_categories, unknown_ign_embed, rainbow_separator, guild_handle, - missing_permissions_embed) + missing_permissions_embed, member_req) from src.utils.db_utils import (delete_dnkl, select_one, get_invites) from src.utils.request_utils import (get_hypixel_player, get_mojang_profile,