From 57407fdbfb1ba2dcb31f7ffa229cba82729f614e Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:22:36 -0500 Subject: [PATCH 01/13] fix: fixed indexing error --- src/utils/db_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/db_utils.py b/src/utils/db_utils.py index 9157238..faca77d 100644 --- a/src/utils/db_utils.py +++ b/src/utils/db_utils.py @@ -140,7 +140,7 @@ async def insert_new_member(discord_id: int, uuid: str, username: str): async def update_member(discord_id: int, uuid: str, username: str): - discord_idExists = (await select_one("SELECT uuid from members WHERE discord_id = (?)", (discord_id,)))[0] + discord_idExists = await select_one("SELECT uuid from members WHERE discord_id = (?)", (discord_id,)) if discord_idExists: await bot.db.execute("UPDATE members SET uuid = (?) and username = (?) WHERE discord_id = (?)", (uuid, username, discord_id)) From bd050fcf148dd76a8174e5be1352ec04db24eb63 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:23:07 -0500 Subject: [PATCH 02/13] feat: new func that checks if a uuid is in the db. if they are, it returns discordid --- src/utils/db_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/db_utils.py b/src/utils/db_utils.py index faca77d..1154f5b 100644 --- a/src/utils/db_utils.py +++ b/src/utils/db_utils.py @@ -147,3 +147,8 @@ async def update_member(discord_id: int, uuid: str, username: str): await bot.db.commit() else: await insert_new_member(discord_id, uuid, username) + + +async def check_uuid_in_db(uuid: str): + discord_id = (await select_one("SELECT discord_id from members WHERE uuid=(?)", (uuid,))) + return discord_id[0] if discord_id else 0 From bfe1e1aedebe2bd01bf1cfcb4d538280afe003f7 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:24:09 -0500 Subject: [PATCH 03/13] feat: generate_rank_upgrade now pings users if they are in the guild discord. --- src/utils/referral_utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index f1efa9c..c0d35f3 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -6,7 +6,7 @@ from src.utils.calculation_utils import get_player_gexp, get_gexp_sorted from src.utils.consts import guild_handle, member_req, active_req, rank_upgrade_channel, \ rank_upgrade_winner_announcement -from src.utils.db_utils import select_one, insert_new_inviter, add_invitee +from src.utils.db_utils import select_one, insert_new_inviter, add_invitee, check_uuid_in_db from src.utils.request_utils import get_mojang_profile, get_player_guild, get_guild_by_name, get_name_by_uuid @@ -90,7 +90,12 @@ async def generate_rank_upgrade(weekly_invites : list): weighted_entries = [uuid for uuid, weight in entries.items() for _ in range(weight)] shuffle(weighted_entries) winner_uuid = choice(weighted_entries) - winner = await get_name_by_uuid(winner_uuid) + + discord_id = await check_uuid_in_db(winner_uuid) + if discord_id: + winner = f"<@{discord_id}>" + else: + winner = await get_name_by_uuid(winner_uuid) winner_gexp = None for uuid, gexp in members: From ac0174022080e97f2f18131cfabb0002a3094eba Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:33:34 -0500 Subject: [PATCH 04/13] feat: leaderboard text that is generated pings users if they are in the db --- src/utils/calculation_utils.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/utils/calculation_utils.py b/src/utils/calculation_utils.py index c8febae..2960a4d 100644 --- a/src/utils/calculation_utils.py +++ b/src/utils/calculation_utils.py @@ -3,7 +3,8 @@ from datetime import datetime, timedelta from src.utils.consts import ChatColor, active_req, member_req, resident_req -from src.utils.request_utils import get_player_guild, get_name_by_uuid, get_hypixel_player +from src.utils.db_utils import check_uuid_in_db +from src.utils.request_utils import get_player_guild, get_name_by_uuid async def get_player_gexp(uuid: str, guild_data: dict = None): @@ -118,17 +119,23 @@ async def get_gexp_sorted(guild_data: dict): return member_gexp -async def generate_lb_text(member_gexp: list, text: str): +async def generate_lb_text(member_gexp: list, text: str, do_ping): # Generate leaderboard text count = 0 for uuid, gexp in member_gexp[:10]: count += 1 - name = await get_name_by_uuid(uuid) - rank, _ = await get_hypixel_player_rank( - await get_hypixel_player(uuid=uuid)) # Ignores value without color formatting + discord_id = await check_uuid_in_db(uuid) + if discord_id and do_ping: + name = f"<@{discord_id}>" + else: + name = await get_name_by_uuid(uuid) + + # rank, _ = await get_hypixel_player_rank( + # await get_hypixel_player(uuid=uuid)) # Ignores value without color formatting # Add new entry to image content ##text += f"&6{count}. {rank} {name} &2{format(gexp, ',d')} Guild Experience" + text += f"> {count}. {name} - {format(gexp, ',d')} Guild Experience" # Add new line if count < 10: From fbe7e9edbbd8cea98214111ac2480ed64bebca22 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:34:05 -0500 Subject: [PATCH 05/13] feat: daily_top is_automatic argument --- src/func/Integer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/func/Integer.py b/src/func/Integer.py index b596d29..11372df 100644 --- a/src/func/Integer.py +++ b/src/func/Integer.py @@ -41,7 +41,7 @@ async def giveawayreroll(self, reroll_number: int = None): return "This giveaway hasn't ended yet!\n`To end it, use ,giveawayend`" await roll_giveaway(self.integer, reroll_number) - async def gtop(self, ctx): + async def gtop(self, ctx, is_automatic=False): # Check no. days requested to prevent errors if self.integer > 6: return discord.Embed(title="Invalid timestamp!", description="You cannot request data this old!", @@ -67,7 +67,7 @@ async def gtop(self, ctx): # Get image data # text = f"&f&lDaily Top: {date}&r%5Cn" text = f"**Daily Top: {date}**\n" - text = await generate_lb_text(member_gexp, text) + text = await generate_lb_text(member_gexp, text, is_automatic) # for x in range(5): # file = await get_jpg_file(f"https://fake-chat.matdoes.dev/render.png?m=custom&d={text}&t=1") From c36462632c092c73677eceb39feefe5bc2874ce6 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:34:30 -0500 Subject: [PATCH 06/13] feat: set the is_automatic argument to true in the loop --- src/utils/loop_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/loop_utils.py b/src/utils/loop_utils.py index a3c4457..7e6e469 100644 --- a/src/utils/loop_utils.py +++ b/src/utils/loop_utils.py @@ -39,7 +39,7 @@ async def before_giveaway_check(): @tasks.loop(hours=24) async def send_gexp_lb(): await asyncio.sleep(1) - file = await Integer(integer=1).gtop(bot.get_channel(daily_lb_channel)) + file = await Integer(integer=1).gtop(bot.get_channel(daily_lb_channel), is_automatic=True) await bot.get_channel(daily_lb_channel).send(file) if datetime.utcnow().weekday() == 0: await bot.get_channel(weekly_lb_channel).send( From bbb761a494949bd21c7ca4d0aba80b766c7644a1 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:37:46 -0500 Subject: [PATCH 07/13] feat: weekly_gexp_lb has an is_automatic parameter --- src/func/General.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/func/General.py b/src/func/General.py index 4f518a3..bedb603 100644 --- a/src/func/General.py +++ b/src/func/General.py @@ -31,7 +31,7 @@ class General: - async def weeklylb(ctx): + async def weeklylb(ctx, is_automatic=False): # Get guild data guild_data = await get_guild_by_name(guild_handle) @@ -42,7 +42,7 @@ async def weeklylb(ctx): # text = "&f&lWeekly Top&r%5Cn" text = "**Weekly Top**\n" - text = await generate_lb_text(member_gexp, text) + text = await generate_lb_text(member_gexp, text, is_automatic) return text # return await get_jpg_file(f"https://fake-chat.matdoes.dev/render.png?m=custom&d={text}&t=1") From 3e7e1b92ccdeb0b671ccc577844af553c0490178 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 16:38:23 -0500 Subject: [PATCH 08/13] feat: set the is_automatic argument to true in the weekly gexp loop --- src/utils/loop_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/loop_utils.py b/src/utils/loop_utils.py index 7e6e469..76fa153 100644 --- a/src/utils/loop_utils.py +++ b/src/utils/loop_utils.py @@ -47,7 +47,8 @@ async def send_gexp_lb(): f"**{(datetime.utcnow() - timedelta(days=7)).strftime('%d %b %Y')} " f"-" f" {datetime.utcnow().strftime('%d %B %Y')}**") - await bot.get_channel(weekly_lb_channel).send(await General.weeklylb(bot.get_channel(weekly_lb_channel))) + await bot.get_channel(weekly_lb_channel).send( + await General.weeklylb(bot.get_channel(weekly_lb_channel), is_automatic=True)) @send_gexp_lb.before_loop From cbae49bc2b709a7e980edd4590c7e595225cf2cf Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 17:02:37 -0500 Subject: [PATCH 09/13] fix: fixed imports --- src/utils/ticket_utils/gvg_application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ticket_utils/gvg_application.py b/src/utils/ticket_utils/gvg_application.py index cdd5d17..fdbe69e 100644 --- a/src/utils/ticket_utils/gvg_application.py +++ b/src/utils/ticket_utils/gvg_application.py @@ -3,9 +3,9 @@ import discord import src.utils.ui_utils as uiutils -from src.utils.calculation_utils import get_hypixel_player from src.utils.consts import unknown_ign_embed, neutral_color, ticket_categories, neg_color, gvg_requirements, \ missing_permissions_embed +from src.utils.request_utils import get_hypixel_player async def gvg_approve(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed, From 1ee5180eddeba4703673f684ace6eb670861fd49 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 17:03:14 -0500 Subject: [PATCH 10/13] feat: altered code to work with updated function --- src/func/General.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/func/General.py b/src/func/General.py index bedb603..2d2db3d 100644 --- a/src/func/General.py +++ b/src/func/General.py @@ -106,12 +106,11 @@ async def rolecheck(ctx, send_ping: bool): continue nick = await name_grabber(discord_member) - uuid_username = await get_db_uuid_username_from_discord_id(discord_member.id) - if not uuid_username: + uuid, username = await get_db_uuid_username_from_discord_id(discord_member.id) + if not uuid and not username: await discord_member.remove_roles(bot.member_role, bot.ally, bot.guest, bot.active_role) await discord_member.add_roles(bot.new_member_role) continue - uuid, username = uuid_username has_tag_permission = await has_tag_perms(discord_member) await progress_message.edit(content=f"Checking {nick} - {discord_member}") From 720f655baa6e7b0156a74ace1401aec20c597a7d Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 17:03:47 -0500 Subject: [PATCH 11/13] fix: updated get_db_uuid_username_from_discord_id to return (None, None) if record not found --- src/utils/db_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/db_utils.py b/src/utils/db_utils.py index 1154f5b..9b7cd5a 100644 --- a/src/utils/db_utils.py +++ b/src/utils/db_utils.py @@ -128,8 +128,8 @@ async def get_invites(inviter_uuid): async def get_db_uuid_username_from_discord_id(discord_id: int): - return await select_one("SELECT uuid, username from members WHERE discord_id = (?)", (discord_id,)) - + res = await select_one("SELECT uuid, username from members WHERE discord_id = (?)", (discord_id,)) + return (res[0], res[1]) if res else (None, None) async def get_db_username_from_uuid(uuid: str): return (await select_one("SELECT username from members WHERE uuid = (?)", (uuid,)))[0] From 8ddf9425dd685018e3a6fd0a9d94200cd90b7e52 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 17:04:15 -0500 Subject: [PATCH 12/13] fix: updated get_db_username_from_uuid to return None if record not found --- src/utils/db_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/db_utils.py b/src/utils/db_utils.py index 9b7cd5a..5589374 100644 --- a/src/utils/db_utils.py +++ b/src/utils/db_utils.py @@ -132,7 +132,8 @@ async def get_db_uuid_username_from_discord_id(discord_id: int): return (res[0], res[1]) if res else (None, None) async def get_db_username_from_uuid(uuid: str): - return (await select_one("SELECT username from members WHERE uuid = (?)", (uuid,)))[0] + username = await select_one("SELECT username from members WHERE uuid = (?)", (uuid,)) + return username[0] if username else username async def insert_new_member(discord_id: int, uuid: str, username: str): await bot.db.execute("INSERT INTO members VALUES (?, ?, ?)", (discord_id, uuid, username)) From afbf8584356f47d650ff58c2db9dceaff64c3023 Mon Sep 17 00:00:00 2001 From: "suspendedtundra2@gmail.com" Date: Thu, 21 Mar 2024 17:04:52 -0500 Subject: [PATCH 13/13] feat: Mojang api is now avoided whenever possible for weekly and daily gexp lb --- 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 2960a4d..f069682 100644 --- a/src/utils/calculation_utils.py +++ b/src/utils/calculation_utils.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta from src.utils.consts import ChatColor, active_req, member_req, resident_req -from src.utils.db_utils import check_uuid_in_db +from src.utils.db_utils import check_uuid_in_db, get_db_username_from_uuid from src.utils.request_utils import get_player_guild, get_name_by_uuid @@ -126,10 +126,11 @@ async def generate_lb_text(member_gexp: list, text: str, do_ping): count += 1 discord_id = await check_uuid_in_db(uuid) + username = await get_db_username_from_uuid(uuid=uuid) if discord_id and do_ping: name = f"<@{discord_id}>" else: - name = await get_name_by_uuid(uuid) + name = await get_name_by_uuid(uuid) if not username else username # rank, _ = await get_hypixel_player_rank( # await get_hypixel_player(uuid=uuid)) # Ignores value without color formatting