-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
9444ecc
to
e825d0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a first brief overview and quick look at the code. I'd recommend at #20 for how I set up views, etc. What I'll more than likely do is to take some of the code in this PR, and merge it with #20 as that PR has a complete full impl of the core tickets system
Also make sure to run the formatters, and check if Pyright and Ruff catches any errors or not
sql/create_user_threads_map.sql
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the built in migrations system in order to handle this. You can use python migrations.py migrate
to create a new revision to work on
bot/cogs/dm_comms.py
Outdated
|
||
async def on_timeout(self) -> None: | ||
if not self._replied: | ||
await self._base_msg.reply("You have not responded within 30 seconds") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I highly don't recommend using discord.Message.reply
, as it quickly becomes annoying. The user already knows that the bot already responded, so it's better to use discord.Message.send
instead
await self._base_msg.reply("You have not responded within 30 seconds") | |
async def on_timeout(self) -> None: | |
if self.message: | |
await self.message.edit(content="You have not responded within 30 seconds") |
also realistically, the 30 second timeout is kinda too little. ~300-500 seconds is a good amount as the user may or may be deciding on whether they should be creating the ticket or not
bot/cogs/dm_comms.py
Outdated
from rodhaj import Rodhaj | ||
|
||
|
||
class StubView(discord.ui.View): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libs.utils.views.RoboView
exists, and is designed to aid with default views
bot/cogs/dm_comms.py
Outdated
@commands.Cog.listener() | ||
async def on_message(self, message: Message): | ||
if isinstance(message.channel, DMChannel): | ||
if message.author not in self._bot.users: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes the classic mistake of thinking discord.Member
has an __eq__
method. If you wish to compare them, compare the ids instead. And I'm not so sure to say about comparing the bot's internal user cache as it might not be accurate (maybe ask soheab about this?)
ee0492a
to
4eed780
Compare
@No767 I believe I fixed most of the issues (aside from formatting or pyright, but I will later today) |
ae89937
to
480f560
Compare
I'll be submitting a review fairly soon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the improvements. I've left some comments
bot/cogs/dm_comms.py
Outdated
if not self._bot.user_is_this_bot(message.author): | ||
await self.handle_dm(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this code lies within the on_message
, this event takes an argument, which is discord.Message
. With this knowledge, the canonical method for preventing bot recursion is shown below:
if message.author.bot:
return
... # do the rest of the code
The way Solstice phrased it was a bit confusing
bot/cogs/dm_comms.py
Outdated
|
||
@commands.Cog.listener() | ||
async def on_message(self, message: Message): | ||
if isinstance(message.channel, DMChannel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cleaner check can be implemented as such:
if isinstance(message.channel, DMChannel): | |
# If the guild associated with the message is None, we know that it has to be a guaranteed to come from a DM instead | |
if message.guild is None: ... |
bot/cogs/dm_comms.py
Outdated
|
||
async def handle_user_no_thread(self, message: Message): | ||
channel = message.channel | ||
context = await self._bot.get_context(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more efficient just to construct the context once as you would need it in both cases anyways
bot/cogs/dm_comms.py
Outdated
|
||
# Code to create thread here | ||
if result: | ||
await channel.send( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message.channel
sends it to the message's channel. I'd not recommend doing this as it can get confusing and does introduce a bug into the code. In reality, use the context here instead
bot/rodhaj.py
Outdated
@@ -83,6 +83,10 @@ def stop(): | |||
self.logger.info("Dev mode is enabled. Loading FSWatcher") | |||
self.loop.create_task(self.fs_watcher()) | |||
|
|||
def user_is_this_bot(self, user: Union[discord.User, discord.Member]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just check the attr of discord.User
's bot
for example:
# Assume we have the user variable, which is the type of discord.User
return user.bot
in reality you probably don't even need this helper method to begin with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted this method
480f560
to
c431687
Compare
for more information, see https://pre-commit.ci
This reverts commit e825d0d.
c431687
to
045f710
Compare
045f710
to
ddb8426
Compare
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 1 New issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks good to me. What I'll probably do is to merge this into main, and then merge it back into my branch (noelle/tickets), and then edit the code as needed on my branch
Closes #8