diff options
author | suhas <hi@suhas.one> | 2023-11-22 23:38:22 -0600 |
---|---|---|
committer | suhas <hi@suhas.one> | 2023-11-22 23:38:22 -0600 |
commit | 7d9f370dedd776d5b4d859818bf2254e21d58102 (patch) | |
tree | d444ca7e8dfc5601fc857618552998ba1fd30120 /cogs | |
parent | c3dfa5bffa3f9da233dccc3c18e62e751688554d (diff) | |
download | qbb-main.tar.gz |
Diffstat (limited to 'cogs')
-rw-r--r-- | cogs/stats.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/cogs/stats.py b/cogs/stats.py index 911d9bf..17304b7 100644 --- a/cogs/stats.py +++ b/cogs/stats.py @@ -1,5 +1,5 @@ from discord.ext.commands import Cog, Bot -from discord.app_commands import command +from discord.app_commands import command, Group from discord import Interaction, Embed, Color, User from prisma import Prisma from common.types import category_field_translations @@ -11,6 +11,28 @@ class Stats(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot super().__init__() + + leaderboard = Group(name="leaderboard", description="Commands for the leaderboard") + + @leaderboard.command(name="global", description="Get global leaderboard") + async def _global(self, ctx: Interaction, category: str) -> None: + db = Prisma() + await db.connect() + top_10 = await db.user.find_many( + take=10, + order={ + 'questions_correct': 'desc' + } + ) + st = '' + for p in top_10: + u = self.bot.get_user(p.id) + if u is None: + u = await self.bot.fetch_user(p.id) + st += f'{u.name} - {p.questions_correct} correct ({p.questions_incorrect} incorrect)\n' + e = Embed(title=f"Top 10 qbbers globally", description=st) + await ctx.response.send_message(embed=e) + await db.disconnect() @command(description="Get your statistics for qbb") async def stats(self, ctx: Interaction, user: Optional[User] = None): |