Skip to content

Commit 8082e64

Browse files
authored
Add DM communications (#31)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>, Reviewed by Noelle
1 parent 25aa351 commit 8082e64

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

bot/cogs/dm_comms.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from discord import Message
2+
from discord.ext import commands
3+
from libs.utils import RoboContext
4+
from rodhaj import Rodhaj
5+
6+
7+
class DmCommunications(commands.Cog):
8+
def __init__(self, bot: Rodhaj):
9+
self._bot = bot
10+
self._pool = bot.pool
11+
12+
async def handle_user_no_thread(self, context: RoboContext):
13+
result = await context.prompt(
14+
"Seems like you do not have an active thread. "
15+
+ "Would you want to create one?",
16+
timeout=600,
17+
delete_after=True,
18+
)
19+
20+
# Code to create thread here
21+
if result:
22+
await context.send(
23+
"Thread created; please use the following "
24+
+ "thread for all further communications."
25+
)
26+
else:
27+
await context.send("No worries!")
28+
29+
async def handle_dm(self, message: Message):
30+
query = """
31+
SELECT id
32+
FROM tickets
33+
WHERE owner_id = $1
34+
"""
35+
row = await self._pool.fetchrow(query, message.author.id)
36+
37+
message_ctx = await self._bot.get_context(message)
38+
if row is None:
39+
await self.handle_user_no_thread(message_ctx)
40+
41+
@commands.Cog.listener()
42+
async def on_message(self, message: Message):
43+
if message.guild is None:
44+
if not message.author.bot:
45+
# private DM not from bot
46+
await self.handle_dm(message)
47+
48+
49+
async def setup(bot: Rodhaj):
50+
await bot.add_cog(DmCommunications(bot))

bot/libs/utils/context.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class ConfirmationView(RoboView):
1515
def __init__(self, ctx, timeout: float, delete_after: bool):
16-
super().__init__(ctx, timeout)
16+
super().__init__(ctx, timeout=timeout)
1717
self.value: Optional[bool] = None
1818
self.delete_after = delete_after
1919
self.message: Optional[discord.Message] = None

0 commit comments

Comments
 (0)