f3397f6f08
* feat: 将 MessageSession 的 platform_id 改为 init=False,实例化时无需传入 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 将 isinstance 检查改为元组、将默认模型值设为空字符串、将类型注解改为 Any 并导入 * refactor: 为 _serialize_job 增加返回类型注解 dict * fix: 使用 cast 获取百度 AIP 的 msg 并对 psutil_addr 引入 type: ignore Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * refactor: 引入 _AddrWithPort 协议并替换 conn.laddr 的 cast Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> * fix: 在构建 AstrBotMessage 时对 ctx.channel 可能为 None 进行兜底处理 Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat> --------- Co-authored-by: aider (openai/gpt-5.2) <aider@aider.chat>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from dataclasses import dataclass, field
|
|
|
|
from astrbot.core.platform.message_type import MessageType
|
|
|
|
|
|
@dataclass
|
|
class MessageSession:
|
|
"""描述一条消息在 AstrBot 中对应的会话的唯一标识。
|
|
如果您需要实例化 MessageSession,请不要给 platform_id 赋值(或者同时给 platform_name 和 platform_id 赋值相同值)。它会在 __post_init__ 中自动设置为 platform_name 的值。
|
|
"""
|
|
|
|
platform_name: str
|
|
"""平台适配器实例的唯一标识符。自 AstrBot v4.0.0 起,该字段实际为 platform_id。"""
|
|
message_type: MessageType
|
|
session_id: str
|
|
platform_id: str = field(init=False)
|
|
|
|
def __str__(self):
|
|
return f"{self.platform_id}:{self.message_type.value}:{self.session_id}"
|
|
|
|
def __post_init__(self):
|
|
self.platform_id = self.platform_name
|
|
|
|
@staticmethod
|
|
def from_str(session_str: str):
|
|
platform_id, message_type, session_id = session_str.split(":", 2)
|
|
return MessageSession(platform_id, MessageType(message_type), session_id)
|
|
|
|
|
|
MessageSesion = MessageSession # back compatibility
|