summary refs log tree commit diff stats
path: root/cogs
diff options
context:
space:
mode:
authorsuhas <hi@suhas.one>2023-11-22 23:38:22 -0600
committersuhas <hi@suhas.one>2023-11-22 23:38:22 -0600
commit7d9f370dedd776d5b4d859818bf2254e21d58102 (patch)
treed444ca7e8dfc5601fc857618552998ba1fd30120 /cogs
parentc3dfa5bffa3f9da233dccc3c18e62e751688554d (diff)
downloadqbb-7d9f370dedd776d5b4d859818bf2254e21d58102.tar.gz
Diffstat (limited to 'cogs')
-rw-r--r--cogs/stats.py24
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):