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

54 lines
1.6 KiB
Python
Raw Permalink Normal View History

2024-08-29 08:48:14 +00:00
from typing import cast
from discord import Embed, Guild, Member
2024-08-28 19:39:55 +00:00
from discord.ext import commands
2024-08-29 08:48:14 +00:00
import lib.format
from lib.client import Luminara
2024-08-28 19:39:55 +00:00
from lib.const import CONST
2024-08-29 08:48:14 +00:00
from ui.embeds import Builder
2024-08-28 19:39:55 +00:00
from ui.views.leaderboard import LeaderboardCommandOptions, LeaderboardCommandView
class Leaderboard(commands.Cog):
def __init__(self, bot: Luminara) -> None:
self.bot: Luminara = bot
self.leaderboard.usage = lib.format.generate_usage(self.leaderboard)
2024-08-28 19:39:55 +00:00
@commands.hybrid_command(
name="leaderboard",
aliases=["lb"],
)
async def leaderboard(self, ctx: commands.Context[Luminara]) -> None:
2024-09-01 12:12:32 +00:00
"""
Get the leaderboard for the server.
Parameters
----------
ctx : commands.Context[Luminara]
2024-09-01 12:12:32 +00:00
The context of the command.
"""
2024-08-29 08:48:14 +00:00
guild: Guild | None = ctx.guild
2024-08-28 19:39:55 +00:00
if not guild:
return
options: LeaderboardCommandOptions = LeaderboardCommandOptions()
view: LeaderboardCommandView = LeaderboardCommandView(ctx, options)
2024-08-29 08:48:14 +00:00
author: Member = cast(Member, ctx.author)
embed: Embed = Builder.create_embed(
Builder.INFO,
2024-08-29 08:48:14 +00:00
user_name=author.name,
thumbnail_url=author.display_avatar.url,
2024-08-28 19:39:55 +00:00
hide_name_in_description=True,
)
icon: str = guild.icon.url if guild.icon else CONST.FLOWERS_ART
await view.populate_leaderboard("xp", embed, icon)
await ctx.send(embed=embed, view=view)
async def setup(bot: Luminara) -> None:
2024-08-28 19:39:55 +00:00
await bot.add_cog(Leaderboard(bot))