Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Add DM communications #31

Merged
merged 10 commits into from
Jan 5, 2024
50 changes: 50 additions & 0 deletions bot/cogs/dm_comms.py
No767 marked this conversation as resolved.
Show resolved Hide resolved
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
No767 marked this conversation as resolved.
Show resolved Hide resolved
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?",
No767 marked this conversation as resolved.
Show resolved Hide resolved
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 = """
No767 marked this conversation as resolved.
Show resolved Hide resolved
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