diff --git a/src/func/General.py b/src/func/General.py index 4f518a3..2d2db3d 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") @@ -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}") 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") diff --git a/src/utils/calculation_utils.py b/src/utils/calculation_utils.py index c8febae..f069682 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, get_db_username_from_uuid +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,24 @@ 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) + 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) if not username else username + + # 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: diff --git a/src/utils/db_utils.py b/src/utils/db_utils.py index 9157238..5589374 100644 --- a/src/utils/db_utils.py +++ b/src/utils/db_utils.py @@ -128,11 +128,12 @@ 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] + 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)) @@ -140,10 +141,15 @@ 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)) 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 diff --git a/src/utils/loop_utils.py b/src/utils/loop_utils.py index a3c4457..76fa153 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( @@ -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 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: 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,