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
|
|
|
|
2024-09-02 08:16:43 +00:00
|
|
|
import lib.format
|
2024-09-03 07:47:46 +00:00
|
|
|
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):
|
2024-09-03 07:47:46 +00:00
|
|
|
def __init__(self, bot: Luminara) -> None:
|
|
|
|
self.bot: Luminara = bot
|
2024-09-02 08:16:43 +00:00
|
|
|
self.leaderboard.usage = lib.format.generate_usage(self.leaderboard)
|
2024-08-28 19:39:55 +00:00
|
|
|
|
|
|
|
@commands.hybrid_command(
|
|
|
|
name="leaderboard",
|
|
|
|
aliases=["lb"],
|
|
|
|
)
|
2024-09-03 07:47:46 +00:00
|
|
|
async def leaderboard(self, ctx: commands.Context[Luminara]) -> None:
|
2024-09-01 12:12:32 +00:00
|
|
|
"""
|
|
|
|
Get the leaderboard for the server.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
2024-09-03 07:47:46 +00:00
|
|
|
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(
|
2024-09-03 10:16:21 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2024-09-03 07:47:46 +00:00
|
|
|
async def setup(bot: Luminara) -> None:
|
2024-08-28 19:39:55 +00:00
|
|
|
await bot.add_cog(Leaderboard(bot))
|