From 7d9f370dedd776d5b4d859818bf2254e21d58102 Mon Sep 17 00:00:00 2001 From: suhas Date: Wed, 22 Nov 2023 23:38:22 -0600 Subject: idk --- cogs/stats.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'cogs') 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): -- cgit 1.4.1-2-gfad0