From a5421ca2aa7c76bebe47e5ee0c7fa43e2d95cf91 Mon Sep 17 00:00:00 2001 From: Amxgh <86120332+Amxgh@users.noreply.github.com> Date: Sat, 25 May 2024 17:31:54 +0400 Subject: [PATCH 1/4] feat: dnklremove now accepts a players uuid and ign --- src/func/String.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/func/String.py b/src/func/String.py index ee2bb0f..b1dd9eb 100644 --- a/src/func/String.py +++ b/src/func/String.py @@ -206,8 +206,12 @@ async def dnkladd(self, ctx): dnkl_embed = await dnkl_application(ign, uuid, ctx.channel, ctx.author, weekly_gexp) async def dnklremove(self): - ign, uuid = await get_mojang_profile(self.string) - row = await select_one("SELECT * FROM dnkl WHERE username = (?)", (ign,)) + if self.string: + ign, uuid = await get_mojang_profile(self.string) + else: + ign, uuid = await get_name_by_uuid(self.uuid), self.uuid + + row = await select_one("SELECT * FROM dnkl WHERE uuid = (?)", (uuid,)) if not row: return "This player is not on the do-not-kick-list!" From 56de9bab27b4821c2bf128e45be1acbb3c425ed9 Mon Sep 17 00:00:00 2001 From: Amxgh <86120332+Amxgh@users.noreply.github.com> Date: Sat, 25 May 2024 17:32:09 +0400 Subject: [PATCH 2/4] feat: added error handling in case hypixel api returns none --- src/utils/request_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/request_utils.py b/src/utils/request_utils.py index 28c6b5b..252e262 100644 --- a/src/utils/request_utils.py +++ b/src/utils/request_utils.py @@ -66,6 +66,8 @@ async def get_hypixel_player(name: str = None, uuid: str = None): else: resp = await get_json_response(f"https://api.hypixel.net/player?key={api_key}&uuid={uuid}") + if not resp: + return None # Player doesn't exist if "player" not in resp or not resp["player"]: return None From 3b3433cb4777af8813d4e486430bbd96e3c13a33 Mon Sep 17 00:00:00 2001 From: Amxgh <86120332+Amxgh@users.noreply.github.com> Date: Sat, 25 May 2024 17:32:26 +0400 Subject: [PATCH 3/4] feat: added an option to dnkl_remove to accept uuids --- src/cogs/hypixel.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cogs/hypixel.py b/src/cogs/hypixel.py index f6c2636..350ec0e 100644 --- a/src/cogs/hypixel.py +++ b/src/cogs/hypixel.py @@ -74,12 +74,26 @@ async def dnkl_add(self, ctx, name: str): @option( name="name", description="The Minecraft username of the player who you want to remove from the do-not-kick-list", - required=True, + required=False, input_type=str ) - async def dnkl_remove(self, ctx, name: str): + @option( + name="uuid", + description="The UUID of the player who you want to remove from the do-not-kick-list", + required=False, + input_type=str + ) + async def dnkl_remove(self, ctx, name: str = None, uuid: str = None): """Remove a player from the do-not-kick-list""" - await ctx.respond(await String(string=name).dnklremove()) + if not name and not uuid: + await ctx.respond("Please provide either the username or the UUID of the player you want to remove.") + return + if name and not uuid and len(name) > 16: + uuid = name + if uuid: + await ctx.respond(await String(uuid=uuid).dnklremove()) + else: + await ctx.respond(await String(string=name).dnklremove()) @bridge.bridge_command(aliases=['dnkllist', 'dnkll']) async def dnkl_list(self, ctx): From 3d0f880934492fa6d5094047909fab7c950d25d6 Mon Sep 17 00:00:00 2001 From: Amxgh <86120332+Amxgh@users.noreply.github.com> Date: Sat, 25 May 2024 17:32:41 +0400 Subject: [PATCH 4/4] feat: dnkl_list prints a user's uuid alongside their name --- 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 0f6eaf5..998d8a8 100644 --- a/src/func/General.py +++ b/src/func/General.py @@ -56,8 +56,8 @@ async def dnkllist(ctx): # Create embed content = "" for _set in rows: - _, _, username = _set - content += f"{username}\n" + _, uuid, username = _set + content += f"{username} ||{uuid}||\n" return discord.Embed(title="The people on the do-not-kick-list are as follows:", description=content, color=neutral_color).set_footer(text=f"Total: {len(content.split())}")