Skip to content

Commit

Permalink
Merge pull request #368 from PyBotDevs/add-user-level-xp-targets-in-r…
Browse files Browse the repository at this point in the history
…ank-cmd

Add user level XP targets in `/rank` command
  • Loading branch information
notsniped authored Apr 19, 2024
2 parents 7d82b2f + 8bf8689 commit 9aac09b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cogs/levelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ 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:
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.set_footer(text="Keep chatting to earn levels!")
await ctx.respond(embed = localembed)
localembed.add_field(name="XP", value=f"{levelling.get_xp(user.id)}/{xpreq} gained")
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(
Expand All @@ -37,7 +41,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)
Expand All @@ -50,7 +54,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)
Expand Down

0 comments on commit 9aac09b

Please sign in to comment.