diff --git a/bot/cogs/dm_comms.py b/bot/cogs/dm_comms.py new file mode 100644 index 0000000..cfa9a0a --- /dev/null +++ b/bot/cogs/dm_comms.py @@ -0,0 +1,50 @@ +from discord import Message +from discord.ext import commands +from libs.utils import RoboContext +from rodhaj import Rodhaj + + +class DmCommunications(commands.Cog): + def __init__(self, bot: Rodhaj): + self._bot = bot + self._pool = bot.pool + + async def handle_user_no_thread(self, context: RoboContext): + result = await context.prompt( + "Seems like you do not have an active thread. " + + "Would you want to create one?", + timeout=600, + delete_after=True, + ) + + # Code to create thread here + if result: + await context.send( + "Thread created; please use the following " + + "thread for all further communications." + ) + else: + await context.send("No worries!") + + async def handle_dm(self, message: Message): + query = """ + SELECT id + FROM tickets + WHERE owner_id = $1 + """ + row = await self._pool.fetchrow(query, message.author.id) + + message_ctx = await self._bot.get_context(message) + if row is None: + await self.handle_user_no_thread(message_ctx) + + @commands.Cog.listener() + async def on_message(self, message: Message): + if message.guild is None: + if not message.author.bot: + # private DM not from bot + await self.handle_dm(message) + + +async def setup(bot: Rodhaj): + await bot.add_cog(DmCommunications(bot)) diff --git a/bot/libs/utils/context.py b/bot/libs/utils/context.py index fa572d5..fa5a363 100644 --- a/bot/libs/utils/context.py +++ b/bot/libs/utils/context.py @@ -13,7 +13,7 @@ class ConfirmationView(RoboView): def __init__(self, ctx, timeout: float, delete_after: bool): - super().__init__(ctx, timeout) + super().__init__(ctx, timeout=timeout) self.value: Optional[bool] = None self.delete_after = delete_after self.message: Optional[discord.Message] = None