From 83aaf2c363554db3d6ed5125d4aefc991c395612 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:04:34 +0530 Subject: [PATCH 1/3] Beautify the code a little bit --- cogs/levelling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index dca8c00..536d58e 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -21,7 +21,7 @@ def __init__(self, bot): description="Shows your rank or another user's rank" ) @option(name="user", description="Who's rank do you want to view?", type=discord.User, default=None) - async def rank(self, ctx: ApplicationContext, user:discord.User=None): + async def rank(self, ctx: ApplicationContext, user: discord.User=None): if user is None: user = ctx.author try: localembed = discord.Embed(title=f"{user.display_name}'s rank", color=color) @@ -37,7 +37,7 @@ async def rank(self, ctx: ApplicationContext, user:discord.User=None): ) @option(name="user", description="Who's rank do you want to edit?", type=discord.User) @option(name="new_rank", description="The new rank you want to set for the user", type=int) - async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:int): + async def edit_rank(self, ctx: ApplicationContext, user: discord.User, new_rank: int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: levelling.set_level(user.id, new_rank) @@ -50,7 +50,7 @@ async def edit_rank(self, ctx: ApplicationContext, user:discord.User, new_rank:i ) @option(name="user", description="Who's rank do you want to edit?", type=discord.User) @option(name="new_xp", description="The new xp count you want to set for the user", type=int) - async def edit_xp(self, ctx: ApplicationContext, user:discord.User, new_xp:int): + async def edit_xp(self, ctx: ApplicationContext, user: discord.User, new_xp: int): if ctx.author.id != 738290097170153472: return await ctx.respond("This command isn't for you.", ephemeral=True) try: levelling.set_xp(user.id, new_xp) From 7e304894340ad8e8a3243d7049c05d18295a4c11 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:08:28 +0530 Subject: [PATCH 2/3] Add user level XP targets in `/rank` command This will provide a little bit more info on how much more XP is required for the user to level up, from their current level. --- cogs/levelling.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 536d58e..38b6685 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -24,9 +24,13 @@ def __init__(self, bot): async def rank(self, ctx: ApplicationContext, user: discord.User=None): if user is None: user = ctx.author try: + xpreq = int() + for level in range(levelling.get_level(ctx.author.id)): + xpreq += 50 + if xpreq >= 5000: break localembed = discord.Embed(title=f"{user.display_name}'s rank", color=color) localembed.add_field(name="Level", value=levelling.get_level(user.id)) - localembed.add_field(name="XP", value=levelling.get_xp(user.id)) + localembed.add_field(name="XP", value=f"{levelling.get_xp(user.id)}/{xpreq} gained") localembed.set_footer(text="Keep chatting to earn levels!") await ctx.respond(embed = localembed) except KeyError: return await ctx.respond("Looks like that user isn't indexed yet. Try again later.", ephemeral=True) From 8bf86898f4ff8d57a7d3c5c332e20f3459c6d6c8 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:11:10 +0530 Subject: [PATCH 3/3] Add a little bit more info to the embed footer --- cogs/levelling.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 38b6685..bfc2a27 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -31,8 +31,8 @@ async def rank(self, ctx: ApplicationContext, user: discord.User=None): localembed = discord.Embed(title=f"{user.display_name}'s rank", color=color) localembed.add_field(name="Level", value=levelling.get_level(user.id)) localembed.add_field(name="XP", value=f"{levelling.get_xp(user.id)}/{xpreq} gained") - localembed.set_footer(text="Keep chatting to earn levels!") - await ctx.respond(embed = localembed) + localembed.set_footer(text="Keep chatting in servers to earn levels!\nYour rank is global across all servers.") + await ctx.respond(embed=localembed) except KeyError: return await ctx.respond("Looks like that user isn't indexed yet. Try again later.", ephemeral=True) @commands.slash_command(