Skip to content

Commit

Permalink
Merge pull request #181 from MiscGuild/backend-redo
Browse files Browse the repository at this point in the history
Backend redo
  • Loading branch information
Amxgh authored Mar 31, 2024
2 parents e365fd5 + 546b8ec commit d8b1a5d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/cogs/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/func/String.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
17 changes: 8 additions & 9 deletions src/utils/calculation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,24 @@ 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)
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

0 comments on commit d8b1a5d

Please sign in to comment.