fix(discord): handle properly /slash commands in channels
This commit is contained in:
committed by
Teknium
parent
9de4a38ce0
commit
2008e997dc
@@ -2962,6 +2962,17 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||||||
parent_channel_id = self._get_parent_channel_id(message.channel)
|
parent_channel_id = self._get_parent_channel_id(message.channel)
|
||||||
|
|
||||||
is_voice_linked_channel = False
|
is_voice_linked_channel = False
|
||||||
|
|
||||||
|
# Save mention-stripped text before auto-threading since create_thread()
|
||||||
|
# can clobber message.content, breaking /command detection in channels.
|
||||||
|
raw_content = message.content.strip()
|
||||||
|
normalized_content = raw_content
|
||||||
|
mention_prefix = False
|
||||||
|
if self._client.user and self._client.user in message.mentions:
|
||||||
|
mention_prefix = True
|
||||||
|
normalized_content = normalized_content.replace(f"<@{self._client.user.id}>", "").strip()
|
||||||
|
normalized_content = normalized_content.replace(f"<@!{self._client.user.id}>", "").strip()
|
||||||
|
message.content = normalized_content
|
||||||
if not isinstance(message.channel, discord.DMChannel):
|
if not isinstance(message.channel, discord.DMChannel):
|
||||||
channel_ids = {str(message.channel.id)}
|
channel_ids = {str(message.channel.id)}
|
||||||
if parent_channel_id:
|
if parent_channel_id:
|
||||||
@@ -2999,13 +3010,8 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||||||
in_bot_thread = is_thread and thread_id in self._threads
|
in_bot_thread = is_thread and thread_id in self._threads
|
||||||
|
|
||||||
if require_mention and not is_free_channel and not in_bot_thread:
|
if require_mention and not is_free_channel and not in_bot_thread:
|
||||||
if self._client.user not in message.mentions:
|
if self._client.user not in message.mentions and not mention_prefix:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._client.user and self._client.user in message.mentions:
|
|
||||||
message.content = message.content.replace(f"<@{self._client.user.id}>", "").strip()
|
|
||||||
message.content = message.content.replace(f"<@!{self._client.user.id}>", "").strip()
|
|
||||||
|
|
||||||
# Auto-thread: when enabled, automatically create a thread for every
|
# Auto-thread: when enabled, automatically create a thread for every
|
||||||
# @mention in a text channel so each conversation is isolated (like Slack).
|
# @mention in a text channel so each conversation is isolated (like Slack).
|
||||||
# Messages already inside threads or DMs are unaffected.
|
# Messages already inside threads or DMs are unaffected.
|
||||||
@@ -3027,7 +3033,7 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||||||
|
|
||||||
# Determine message type
|
# Determine message type
|
||||||
msg_type = MessageType.TEXT
|
msg_type = MessageType.TEXT
|
||||||
if message.content.startswith("/"):
|
if normalized_content.startswith("/"):
|
||||||
msg_type = MessageType.COMMAND
|
msg_type = MessageType.COMMAND
|
||||||
elif message.attachments:
|
elif message.attachments:
|
||||||
# Check attachment types
|
# Check attachment types
|
||||||
@@ -3167,7 +3173,9 @@ class DiscordAdapter(BasePlatformAdapter):
|
|||||||
att.filename, e, exc_info=True,
|
att.filename, e, exc_info=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
event_text = message.content
|
# Use normalized_content (saved before auto-threading) instead of message.content,
|
||||||
|
# to detect /slash commands in channel messages.
|
||||||
|
event_text = normalized_content
|
||||||
if pending_text_injection:
|
if pending_text_injection:
|
||||||
event_text = f"{pending_text_injection}\n\n{event_text}" if event_text else pending_text_injection
|
event_text = f"{pending_text_injection}\n\n{event_text}" if event_text else pending_text_injection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user