Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions astrbot/core/platform/astr_message_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(
self.is_at_or_wake_command = False
"""是否是 At 机器人或者带有唤醒词或者是私聊(插件注册的事件监听器会让 is_wake 设为 True, 但是不会让这个属性置为 True)"""
self._extras: dict[str, Any] = {}
self._force_stopped: bool = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository rules, new functionality should be accompanied by corresponding unit tests. Since this PR introduces a new state management mechanism for event propagation, adding a test case to verify that is_stopped() remains True after clear_result() would be beneficial to prevent future regressions.

References
  1. New functionality, such as handling attachments, should be accompanied by corresponding unit tests.

"""独立的停止标志,不依赖 _result,不会被 clear_result() 重置"""
message_type = getattr(message_obj, "type", None)
if not isinstance(message_type, MessageType):
try:
Expand Down Expand Up @@ -336,20 +338,24 @@ async def check_count(self, event: AstrMessageEvent):

def stop_event(self) -> None:
"""终止事件传播。"""
self._force_stopped = True
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this change correctly handles stop_event(), it's worth noting that set_result() can also be used to stop an event (e.g., event.set_result(MessageEventResult().stop_event())). In such cases, _force_stopped will remain False, and the stop state will still be lost if clear_result() is called. Although set_result is not modified in this diff, consider updating _force_stopped within that method as well to ensure consistent behavior across all ways of stopping an event.

if self._result is None:
self.set_result(MessageEventResult().stop_event())
else:
self._result.stop_event()

def continue_event(self) -> None:
"""继续事件传播。"""
self._force_stopped = False
if self._result is None:
self.set_result(MessageEventResult().continue_event())
else:
self._result.continue_event()

def is_stopped(self) -> bool:
"""是否终止事件传播。"""
if self._force_stopped:
return True
if self._result is None:
return False # 默认是继续传播
return self._result.is_stopped()
Expand Down
Loading