summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--bot.py15
-rw-r--r--cogs/stats.py24
2 files changed, 32 insertions, 7 deletions
diff --git a/bot.py b/bot.py
index 6c3dcd3..987cb00 100644
--- a/bot.py
+++ b/bot.py
@@ -11,13 +11,17 @@ import asyncio
 
 load_dotenv()
 
-if getenv('TOKEN') is None or getenv('OWNER_ID') is None:
+token = getenv('TOKEN')
+owner_id = getenv('OWNER_ID')
+if token is None or owner_id is None:
     print('please set a TOKEN and OWNER_ID environment variable')
     exit(1)
 
 class QBBBot(Bot):
     def __init__(self) -> None:
-        super().__init__(command_prefix=when_mentioned, intents=Intents.default())
+        i = Intents.default()
+        i.members = True
+        super().__init__(command_prefix=when_mentioned, intents=i)
 
     async def setup_hook(self):
         await self.load_extension('cogs.tossup')
@@ -28,16 +32,15 @@ class QBBBot(Bot):
 
 
 bot = QBBBot()
-bot.qb_categories = Literal['Literature', 'History', 'Science', 'Fine Arts', 'Religion', 'Mythology', 'Philosophy',
-                            'Social Science', 'Current Events', 'Geography', 'Other Academic', 'Trash']
+
 
 
 @bot.command()
 async def sync(ctx: Context):
-    if str(ctx.author.id) == getenv('OWNER_ID'):
+    if str(ctx.author.id) == owner_id:
         await bot.tree.sync()
         await ctx.send('ok')
     else:
         await ctx.send('no')
 
-bot.run(getenv('TOKEN'))
+bot.run(token)
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):