-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: breaking threadmenu fixes. #3425
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
Open
lorenzo132
wants to merge
19
commits into
development
Choose a base branch
from
users/lorenzo/breaking-threadmenu-fix
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7322e99
Update gitignore
Taaku18 c3edf86
fix: breaking threadmenu fixes.
lorenzo132 78aec10
fix: thread_auto_close bug.
lorenzo132 589ba50
Merge branch 'development' into users/lorenzo/breaking-threadmenu-fix
lorenzo132 ab863db
Replace claim plugin (#3437)
martinbndr fdbef3d
Feat: Renaming of snippets and aliases (#3383)
martinbndr cea1800
Fixes config_help notes (#3407)
martinbndr 0aae3f6
Git Repository check for bot update (#3406)
martinbndr 16f2ba6
Fix Plugin Help (#3322)
martinbndr ea29d8f
Added submenu functionality to threadmenu. Fixes #3403 (#3404)
sebkuip 2fbd7e5
Fix: Blackformatting, workflows. Add snooze/unsnooze events. (#3412)
lorenzo132 9833766
Add threadmenu toggle notice (#3411)
martinbndr 367bb3d
Improvements for alias creation/editing (#3422)
martinbndr cb86a02
Fixes thread_auto_close execution when disabled. (#3423)
martinbndr 6e656ca
fix: breaking threadmenu fixes.
lorenzo132 f089ba3
fix: thread_auto_close bug.
lorenzo132 b68d82a
fix: plain replies deletion and edits (#3416)
lorenzo132 90371cc
Merge branch 'users/lorenzo/breaking-threadmenu-fix' of https://githu…
lorenzo132 dff4a62
Merge branch 'development' into users/lorenzo/breaking-threadmenu-fix
lorenzo132 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,7 @@ def cancelled(self) -> bool: | |
| def cancelled(self, flag: bool): | ||
| self._cancelled = flag | ||
| if flag: | ||
| self._ready_event.set() | ||
| for i in self.wait_tasks: | ||
| i.cancel() | ||
|
|
||
|
|
@@ -1781,6 +1782,13 @@ async def send( | |
| reply commands to avoid mutating the original message object. | ||
| """ | ||
| # Handle notes with Discord-like system message format - return early | ||
| if message is None: | ||
| # Safeguard against None messages (e.g. from menu interactions without a source message) | ||
| if not note and not from_mod and not thread_creation: | ||
| # If we're just trying to log/relay a user message and there is none, existing behavior | ||
| # suggests we might skip or error. Logging a warning and returning is safer than crashing. | ||
| return | ||
|
|
||
| if note: | ||
| destination = destination or self.channel | ||
| content = message.content or "[No content]" | ||
|
|
@@ -1835,7 +1843,8 @@ async def send( | |
| await self.wait_until_ready() | ||
|
|
||
| if not from_mod and not note: | ||
| self.bot.loop.create_task(self.bot.api.append_log(message, channel_id=self.channel.id)) | ||
| if self.channel: | ||
| self.bot.loop.create_task(self.bot.api.append_log(message, channel_id=self.channel.id)) | ||
|
|
||
| destination = destination or self.channel | ||
|
|
||
|
|
@@ -2558,6 +2567,10 @@ async def create( | |
| # checks for existing thread in cache | ||
| thread = self.cache.get(recipient.id) | ||
| if thread: | ||
| # If there's a pending menu, return the existing thread to avoid creating duplicates | ||
| if getattr(thread, "_pending_menu", False): | ||
| logger.debug("Thread for %s has pending menu, returning existing thread.", recipient) | ||
| return thread | ||
| try: | ||
| await thread.wait_until_ready() | ||
| except asyncio.CancelledError: | ||
|
|
@@ -2566,8 +2579,8 @@ async def create( | |
| label = f"{recipient} ({recipient.id})" | ||
| except Exception: | ||
| label = f"User ({getattr(recipient, 'id', 'unknown')})" | ||
| logger.warning("Thread for %s cancelled, abort creating.", label) | ||
| return thread | ||
| self.cache.pop(recipient.id, None) | ||
| thread = None | ||
| else: | ||
| if thread.channel and self.bot.get_channel(thread.channel.id): | ||
| logger.warning("Found an existing thread for %s, abort creating.", recipient) | ||
|
|
@@ -2915,35 +2928,36 @@ async def callback(self, interaction: discord.Interaction): | |
| setattr(self.outer_thread, "_pending_menu", False) | ||
| return | ||
| # Forward the user's initial DM to the thread channel | ||
| try: | ||
| await self.outer_thread.send(message) | ||
| except Exception: | ||
| logger.error( | ||
| "Failed to relay initial message after menu selection", | ||
| exc_info=True, | ||
| ) | ||
| else: | ||
| # React to the user's DM with the 'sent' emoji | ||
| if message: | ||
| try: | ||
| ( | ||
| sent_emoji, | ||
| _, | ||
| ) = await self.outer_thread.bot.retrieve_emoji() | ||
| await self.outer_thread.bot.add_reaction(message, sent_emoji) | ||
| except Exception as e: | ||
| logger.debug( | ||
| "Failed to add sent reaction to user's DM: %s", | ||
| e, | ||
| await self.outer_thread.send(message) | ||
| except Exception: | ||
| logger.error( | ||
| "Failed to relay initial message after menu selection", | ||
| exc_info=True, | ||
| ) | ||
| else: | ||
| # React to the user's DM with the 'sent' emoji | ||
| try: | ||
| ( | ||
| sent_emoji, | ||
| _, | ||
| ) = await self.outer_thread.bot.retrieve_emoji() | ||
| await self.outer_thread.bot.add_reaction(message, sent_emoji) | ||
| except Exception as e: | ||
| logger.debug( | ||
| "Failed to add sent reaction to user's DM: %s", | ||
| e, | ||
| ) | ||
| # Dispatch thread_reply event for parity | ||
| self.outer_thread.bot.dispatch( | ||
| "thread_reply", | ||
| self.outer_thread, | ||
| False, | ||
| message, | ||
| False, | ||
| False, | ||
| ) | ||
| # Dispatch thread_reply event for parity | ||
| self.outer_thread.bot.dispatch( | ||
| "thread_reply", | ||
| self.outer_thread, | ||
| False, | ||
| message, | ||
| False, | ||
| False, | ||
| ) | ||
| # Clear pending flag | ||
| setattr(self.outer_thread, "_pending_menu", False) | ||
| except Exception: | ||
|
|
@@ -2964,7 +2978,34 @@ async def callback(self, interaction: discord.Interaction): | |
| # Create a synthetic message object that makes the bot appear | ||
| # as the author for menu-invoked command replies so the user | ||
| # selecting the option is not shown as a "mod" sender. | ||
| synthetic = DummyMessage(copy.copy(message)) | ||
| if message: | ||
| synthetic = DummyMessage(copy.copy(message)) | ||
| else: | ||
| # Fallback if no message exists (e.g. self-created thread via menu) | ||
| # We use the interaction's message or construct a minimal dummy | ||
| base_msg = getattr(interaction, "message", None) or self.menu_msg | ||
| synthetic = ( | ||
| DummyMessage(copy.copy(base_msg)) if base_msg else DummyMessage(None) | ||
| ) | ||
| # Ensure minimal attributes for Context if still missing (DummyMessage handles some, but we need more for commands) | ||
| if not synthetic._message: | ||
| # Identify a valid channel | ||
| ch = self.outer_thread.channel | ||
| if not ch: | ||
| # If channel isn't ready, we can't really invoke a command in it. | ||
| continue | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't make imports halfway into the file. Also is a unittest class really the only way to do this? This isn't the intended way to use this class. |
||
|
|
||
| # Create a mock message strictly for command invocation context | ||
| mock_msg = MagicMock(spec=discord.Message) | ||
| mock_msg.id = 0 | ||
| mock_msg.channel = ch | ||
| mock_msg.guild = self.outer_thread.bot.modmail_guild | ||
| mock_msg.content = self.outer_thread.bot.prefix + al | ||
| mock_msg.author = self.outer_thread.bot.user | ||
| synthetic = DummyMessage(mock_msg) | ||
|
|
||
| try: | ||
| synthetic.author = ( | ||
| self.outer_thread.bot.modmail_guild.me or self.outer_thread.bot.user | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In the old code, the bot would extract forwarded content. Now it's falling back to regular message.content, which would break if the message is a forward.