summary refs log tree commit diff stats
path: root/cogs
diff options
context:
space:
mode:
authorsuhas <hi@suhas.one>2023-11-02 23:28:24 -0500
committersuhas <hi@suhas.one>2023-11-02 23:28:24 -0500
commit0db6d876288da45b8c4814407fcbae4c02314cc0 (patch)
tree1c9f0cea64b33e7ae8500a02410b31a94ecc4137 /cogs
downloadqbb-0db6d876288da45b8c4814407fcbae4c02314cc0.tar.gz
first commit
Diffstat (limited to 'cogs')
-rw-r--r--cogs/__pycache__/solo.cpython-311.pycbin0 -> 3787 bytes
-rw-r--r--cogs/__pycache__/tossup.cpython-311.pycbin0 -> 3805 bytes
-rw-r--r--cogs/solo.py41
-rw-r--r--cogs/tossup.py42
4 files changed, 83 insertions, 0 deletions
diff --git a/cogs/__pycache__/solo.cpython-311.pyc b/cogs/__pycache__/solo.cpython-311.pyc
new file mode 100644
index 0000000..6ede884
--- /dev/null
+++ b/cogs/__pycache__/solo.cpython-311.pyc
Binary files differdiff --git a/cogs/__pycache__/tossup.cpython-311.pyc b/cogs/__pycache__/tossup.cpython-311.pyc
new file mode 100644
index 0000000..08b770b
--- /dev/null
+++ b/cogs/__pycache__/tossup.cpython-311.pyc
Binary files differdiff --git a/cogs/solo.py b/cogs/solo.py
new file mode 100644
index 0000000..aab0b77
--- /dev/null
+++ b/cogs/solo.py
@@ -0,0 +1,41 @@
+from discord.ext.commands import GroupCog, Bot
+from discord.ui import View, Button, Modal, button, TextInput
+from discord.app_commands import command
+from discord import Interaction, Embed, User, Member, ButtonStyle, Color
+from httpx import AsyncClient
+from nltk import sent_tokenize
+from typing import Union, Optional
+from common.types import question_category
+from components.TossupButtons import SoloTossupButtons
+
+
+class Solo(GroupCog, name="solo"):
+    def __init__(self, bot: Bot) -> None:
+        self.bot = bot
+        super().__init__()
+
+    @command(description="Do a tossup in solo mode (only you can control the tossup)")
+    async def tossup(self, ctx: Interaction, category: Optional[question_category] = None):
+        c = AsyncClient()
+        params = {'difficulties': [2,3,4,5]}
+        if category is not None:
+            params['categories'] = category
+
+        req = await c.get(
+            "https://qbreader.org/api/random-tossup", params=params
+        )
+        tossup: dict = req.json()["tossups"][0]
+        tossup['sentences'] = await self.bot.loop.run_in_executor(None, sent_tokenize, tossup['question'])
+
+
+        view: SoloTossupButtons = SoloTossupButtons(tossup, ctx.user)
+        embed = Embed(title="Random Tossup", description=tossup["sentences"][0])
+        embed.set_author(
+            name=f"{tossup['set']['name']} Packet {tossup['packetNumber']} Question {tossup['questionNumber']}"
+        )
+        embed.set_footer(text="Questions obtained from qbreader.org")
+        await ctx.response.send_message(embed=embed, view=view)
+        await c.aclose()
+
+async def setup(bot: Bot) -> None:
+    await bot.add_cog(Solo(bot))
diff --git a/cogs/tossup.py b/cogs/tossup.py
new file mode 100644
index 0000000..ae01519
--- /dev/null
+++ b/cogs/tossup.py
@@ -0,0 +1,42 @@
+from discord.ext.commands import Cog, Bot
+from discord.app_commands import command, describe
+from discord import Interaction, Embed, ButtonStyle
+from discord.ui import View, Button, Modal, button, TextInput
+from nltk import sent_tokenize
+from httpx import AsyncClient
+from typing import Literal, Optional
+from common.types import question_category
+from components.AnswerModal import Answer
+from components.TossupButtons import TossupButtons
+
+class Tossup(Cog):
+    def __init__(self, bot: Bot) -> None:
+        self.bot = bot
+
+    @command(name="tossup", description="gives a random tossup")
+    @describe(category="The category to choose the question from (optional)")
+    async def tossup(self, ctx: Interaction, category: Optional[question_category] = None):
+        c = AsyncClient()
+
+        params = {"difficulties": [2, 3, 4, 5]}
+        if category is not None:
+            params["categories"] = category
+
+        req = await c.get("https://qbreader.org/api/random-tossup", params=params)
+        tossup: dict = req.json()["tossups"][0]
+        tossup["sentences"] = await self.bot.loop.run_in_executor(
+            None, sent_tokenize, tossup["question"]
+        )
+
+        view: TossupButtons = TossupButtons(tossup)
+        embed = Embed(title="Random Tossup", description=tossup["sentences"][0])
+        embed.set_author(
+            name=f"{tossup['set']['name']} Packet {tossup['packetNumber']} Question {tossup['questionNumber']} (Category: {tossup['category']})"
+        )
+        embed.set_footer(text="Questions obtained from qbreader.org")
+        await ctx.response.send_message(embed=embed, view=view)
+        await c.aclose()
+
+
+async def setup(bot: Bot) -> None:
+    await bot.add_cog(Tossup(bot))