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
Merged

draft: Add DM communications #31

merged 10 commits into from
Jan 5, 2024

Conversation

jamievlin
Copy link
Member

Closes #8

@jamievlin jamievlin requested a review from No767 December 19, 2023 01:14
@jamievlin jamievlin self-assigned this Dec 19, 2023
@jamievlin jamievlin force-pushed the jamie/dm-comms branch 2 times, most recently from 9444ecc to e825d0d Compare December 19, 2023 01:21
Copy link
Member

@No767 No767 left a 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

Copy link
Member

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


async def on_timeout(self) -> None:
if not self._replied:
await self._base_msg.reply("You have not responded within 30 seconds")
Copy link
Member

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

Suggested change
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

from rodhaj import Rodhaj


class StubView(discord.ui.View):
Copy link
Member

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 Show resolved Hide resolved
bot/cogs/dm_comms.py Show resolved Hide resolved
bot/cogs/dm_comms.py Outdated Show resolved Hide resolved
@commands.Cog.listener()
async def on_message(self, message: Message):
if isinstance(message.channel, DMChannel):
if message.author not in self._bot.users:
Copy link
Member

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?)

@jamievlin jamievlin force-pushed the jamie/dm-comms branch 2 times, most recently from ee0492a to 4eed780 Compare December 22, 2023 21:08
@jamievlin
Copy link
Member Author

jamievlin commented Dec 22, 2023

@No767 I believe I fixed most of the issues (aside from formatting or pyright, but I will later today)

@jamievlin jamievlin force-pushed the jamie/dm-comms branch 2 times, most recently from ae89937 to 480f560 Compare December 22, 2023 21:14
@jamievlin jamievlin requested a review from No767 December 22, 2023 21:15
@No767
Copy link
Member

No767 commented Dec 23, 2023

I'll be submitting a review fairly soon

Copy link
Member

@No767 No767 left a 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

Comment on lines 43 to 46
if not self._bot.user_is_this_bot(message.author):
await self.handle_dm(message)
Copy link
Member

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


@commands.Cog.listener()
async def on_message(self, message: Message):
if isinstance(message.channel, DMChannel):
Copy link
Member

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:

Suggested change
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 Show resolved Hide resolved
bot/cogs/dm_comms.py Show resolved Hide resolved

async def handle_user_no_thread(self, message: Message):
channel = message.channel
context = await self._bot.get_context(message)
Copy link
Member

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


# Code to create thread here
if result:
await channel.send(
Copy link
Member

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]):
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted this method

Copy link

sonarcloud bot commented Jan 5, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@jamievlin jamievlin requested a review from No767 January 5, 2024 08:11
@jamievlin jamievlin marked this pull request as ready for review January 5, 2024 08:12
Copy link
Member

@No767 No767 left a 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

@No767 No767 merged commit 8082e64 into main Jan 5, 2024
9 checks passed
@No767 No767 mentioned this pull request Jan 5, 2024
@No767 No767 deleted the jamie/dm-comms branch January 6, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DM Communication
2 participants