Skip to content

Commit

Permalink
Add DM communications (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>, Reviewed by Noelle
  • Loading branch information
jamievlin authored Jan 5, 2024
1 parent 25aa351 commit 8082e64
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions bot/cogs/dm_comms.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion bot/libs/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8082e64

Please sign in to comment.