fix: unique session not working (#4490)

* fix: unique session not working

* fix: correct session initialization and update unified_msg_origin setter

* fix: update session ID assignment in WakingCheckStage
This commit is contained in:
Soulter
2026-01-15 22:16:21 +08:00
committed by GitHub
parent af2b3b3bfc
commit dbdb4f5185
+23 -4
View File
@@ -42,8 +42,6 @@ class AstrMessageEvent(abc.ABC):
"""消息对象, AstrBotMessage。带有完整的消息结构。""" """消息对象, AstrBotMessage。带有完整的消息结构。"""
self.platform_meta = platform_meta self.platform_meta = platform_meta
"""消息平台的信息, 其中 name 是平台的类型,如 aiocqhttp""" """消息平台的信息, 其中 name 是平台的类型,如 aiocqhttp"""
self.session_id = session_id
"""用户的会话 ID。可以直接使用下面的 unified_msg_origin"""
self.role = "member" self.role = "member"
"""用户是否是管理员。如果是管理员,这里是 admin""" """用户是否是管理员。如果是管理员,这里是 admin"""
self.is_wake = False self.is_wake = False
@@ -51,12 +49,12 @@ class AstrMessageEvent(abc.ABC):
self.is_at_or_wake_command = False self.is_at_or_wake_command = False
"""是否是 At 机器人或者带有唤醒词或者是私聊(插件注册的事件监听器会让 is_wake 设为 True, 但是不会让这个属性置为 True)""" """是否是 At 机器人或者带有唤醒词或者是私聊(插件注册的事件监听器会让 is_wake 设为 True, 但是不会让这个属性置为 True)"""
self._extras: dict[str, Any] = {} self._extras: dict[str, Any] = {}
self.session = MessageSesion( self.session = MessageSession(
platform_name=platform_meta.id, platform_name=platform_meta.id,
message_type=message_obj.type, message_type=message_obj.type,
session_id=session_id, session_id=session_id,
) )
self.unified_msg_origin = str(self.session) # self.unified_msg_origin = str(self.session)
"""统一的消息来源字符串。格式为 platform_name:message_type:session_id""" """统一的消息来源字符串。格式为 platform_name:message_type:session_id"""
self._result: MessageEventResult | None = None self._result: MessageEventResult | None = None
"""消息事件的结果""" """消息事件的结果"""
@@ -72,6 +70,27 @@ class AstrMessageEvent(abc.ABC):
# back_compability # back_compability
self.platform = platform_meta self.platform = platform_meta
@property
def unified_msg_origin(self) -> str:
"""统一的消息来源字符串。格式为 platform_name:message_type:session_id"""
return str(self.session)
@unified_msg_origin.setter
def unified_msg_origin(self, value: str):
"""设置统一的消息来源字符串。格式为 platform_name:message_type:session_id"""
self.new_session = MessageSession.from_str(value)
self.session = self.new_session
@property
def session_id(self) -> str:
"""用户的会话 ID。可以直接使用下面的 unified_msg_origin"""
return self.session.session_id
@session_id.setter
def session_id(self, value: str):
"""设置用户的会话 ID。可以直接使用下面的 unified_msg_origin"""
self.session.session_id = value
def get_platform_name(self): def get_platform_name(self):
"""获取这个事件所属的平台的类型(如 aiocqhttp, slack, discord 等)。 """获取这个事件所属的平台的类型(如 aiocqhttp, slack, discord 等)。