1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00
Lumi/modules/levels/level.py

55 lines
1.5 KiB
Python
Raw Normal View History

2024-08-28 16:26:02 +00:00
from discord import Embed
2024-08-29 08:48:14 +00:00
from discord.ext import commands
2024-08-28 16:26:02 +00:00
from lib.const import CONST
from services.xp_service import XpService
2024-08-29 08:48:14 +00:00
from ui.embeds import Builder
2024-08-28 16:26:02 +00:00
class Level(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.hybrid_command(
name="level",
aliases=["rank", "lvl", "xp"],
)
async def ping(self, ctx: commands.Context[commands.Bot]) -> None:
2024-09-01 12:12:32 +00:00
"""
Get the level of the user.
Parameters
----------
ctx : commands.Context[commands.Bot]
The context of the command.
"""
2024-08-28 16:26:02 +00:00
if not ctx.guild:
return
xp_data: XpService = XpService(ctx.author.id, ctx.guild.id)
rank: str = str(xp_data.calculate_rank())
needed_xp_for_next_level: int = XpService.xp_needed_for_next_level(
xp_data.level,
)
2024-08-29 08:48:14 +00:00
embed: Embed = Builder.create_embed(
2024-08-28 16:26:02 +00:00
theme="success",
user_name=ctx.author.name,
title=CONST.STRINGS["xp_level"].format(xp_data.level),
footer_text=CONST.STRINGS["xp_server_rank"].format(rank or "NaN"),
thumbnail_url=ctx.author.display_avatar.url,
hide_name_in_description=True,
)
embed.add_field(
name=CONST.STRINGS["xp_progress"],
value=XpService.generate_progress_bar(xp_data.xp, needed_xp_for_next_level),
inline=False,
)
await ctx.send(embed=embed)
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(Level(bot))