readmeupdate

This commit is contained in:
2026-01-01 20:38:53 +08:00
parent 9b5be6f56e
commit f0844edefd
3 changed files with 442 additions and 11 deletions

View File

@@ -52,3 +52,45 @@ class MessageSegment:
def __repr__(self):
return f"[MS:{self.type}:{self.data}]"
# --- 快捷构造方法 ---
@staticmethod
def text(text: str) -> "MessageSegment":
"""
构造文本消息段
:param text: 文本内容
:return: MessageSegment 对象
"""
return MessageSegment(type="text", data={"text": text})
@staticmethod
def at(user_id: int | str) -> "MessageSegment":
"""
构造 @某人 消息段
:param user_id: 目标 QQ 号,"all" 表示 @全体成员
:return: MessageSegment 对象
"""
return MessageSegment(type="at", data={"qq": str(user_id)})
@staticmethod
def image(file: str) -> "MessageSegment":
"""
构造图片消息段
:param file: 图片文件名、URL 或 Base64
:return: MessageSegment 对象
"""
return MessageSegment(type="image", data={"file": file})
@staticmethod
def face(id: int) -> "MessageSegment":
"""
构造表情消息段
:param id: 表情 ID
:return: MessageSegment 对象
"""
return MessageSegment(type="face", data={"id": str(id)})