mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
Add level command
This commit is contained in:
parent
afd2abfe35
commit
c9c56e20f8
2 changed files with 52 additions and 3 deletions
|
@ -13,9 +13,12 @@ class CogLoader(commands.Cog):
|
|||
async def is_cog(self, path: Path) -> bool:
|
||||
cog_name: str = path.stem
|
||||
|
||||
if cog_name in self.cog_ignore_list:
|
||||
logger.debug(f"Ignoring cog: {cog_name} because it is in the ignore list")
|
||||
return False
|
||||
|
||||
return (
|
||||
path.suffix == ".py"
|
||||
and cog_name not in self.cog_ignore_list
|
||||
and not path.name.startswith("_")
|
||||
and await aiofiles.os.path.isfile(path)
|
||||
)
|
||||
|
@ -30,7 +33,7 @@ class CogLoader(commands.Cog):
|
|||
logger.exception(f"Error loading cog from {item}: {e}")
|
||||
|
||||
elif await self.is_cog(path):
|
||||
relative_path: Path = path.relative_to(Path(__file__).parent)
|
||||
relative_path: Path = path.relative_to(Path(__file__).parent.parent)
|
||||
module: str = (
|
||||
str(relative_path).replace("/", ".").replace("\\", ".")[:-3]
|
||||
)
|
||||
|
@ -45,7 +48,7 @@ class CogLoader(commands.Cog):
|
|||
logger.exception(f"Error loading cogs from {path}: {e}")
|
||||
|
||||
async def load_cog_from_dir(self, dir_name: str) -> None:
|
||||
path: Path = Path(__file__).parent / dir_name
|
||||
path: Path = Path(__file__).parent.parent / dir_name
|
||||
await self.load_cogs(path)
|
||||
|
||||
@classmethod
|
||||
|
|
46
modules/levels/level.py
Normal file
46
modules/levels/level.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
from discord.ext import commands
|
||||
from discord import Embed
|
||||
from lib.const import CONST
|
||||
from ui.embeds import builder
|
||||
from services.xp_service import XpService
|
||||
|
||||
|
||||
class Level(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="level",
|
||||
aliases=["rank", "lvl", "xp"],
|
||||
usage="level",
|
||||
)
|
||||
async def ping(self, ctx: commands.Context[commands.Bot]) -> None:
|
||||
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,
|
||||
)
|
||||
|
||||
embed: Embed = builder.create_embed(
|
||||
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))
|
Loading…
Reference in a new issue