Skip to content

Commit

Permalink
fix: Improve bot mention detection and add error logging in dispatch …
Browse files Browse the repository at this point in the history
…rules
  • Loading branch information
lss233 committed Feb 19, 2025
1 parent 5dbd3fb commit 9840cfb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/im/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __str__(self) -> str:

def __eq__(self, other: Any) -> bool:
if isinstance(other, ChatSender):
print(self.user_id, other.user_id)
return self.user_id == other.user_id and \
self.chat_type == other.chat_type and \
self.group_id == other.group_id
Expand Down
3 changes: 3 additions & 0 deletions framework/workflow/core/dispatch/models/dispatch_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from framework.im.message import IMMessage
from framework.ioc.container import DependencyContainer
from framework.logger import get_logger
from framework.workflow.core.workflow import Workflow
from framework.workflow.core.workflow.registry import WorkflowRegistry

logger = get_logger("DispatchRule")

class SimpleDispatchRule(BaseModel):
"""简单规则,包含规则类型和配置"""
Expand Down Expand Up @@ -56,6 +58,7 @@ def match(self, message: IMMessage, workflow_registry: WorkflowRegistry) -> bool
rule_results.append(rule_instance.match(message))
except Exception as e:
# 如果规则创建或匹配过程出错,视为不匹配
logger.error(f"Rule {rule.type} from config {rule.config} creation or matching failed: {e}")
continue

# 根据操作符确定组的匹配结果
Expand Down
4 changes: 2 additions & 2 deletions framework/workflow/core/dispatch/rules/message_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import Field

from framework.im.message import IMMessage
from framework.im.message import IMMessage, MentionElement
from framework.im.sender import ChatSender
from framework.workflow.core.workflow.registry import WorkflowRegistry

Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self, workflow_registry: WorkflowRegistry, workflow_id: str):

def match(self, message: IMMessage) -> bool:
bot_sender = ChatSender.get_bot_sender()
return any(element.type == "mention" and element.target == bot_sender for element in message.message_elements)
return any(isinstance(element, MentionElement) and element.target == bot_sender for element in message.message_elements)

def get_config(self) -> RuleConfig:
return RuleConfig()
Expand Down

0 comments on commit 9840cfb

Please sign in to comment.