跳转至

segment

本模块实现了 OneBot 消息段。

Segment

Bases: Struct

消息段类型。

Source code in src/pylibob/segment.py
class Segment(Struct):
    """消息段类型。"""

    type: str  # noqa: A003
    data: dict[str, Any]

Audio(file_id, **extra)

音频消息段。

Source code in src/pylibob/segment.py
def Audio(file_id: str, **extra: Any) -> Segment:
    """音频消息段。"""
    return Segment(type="audio", data={"file_id": file_id, **extra})

File(file_id, **extra)

文件消息段。

Source code in src/pylibob/segment.py
def File(file_id: str, **extra: Any) -> Segment:
    """文件消息段。"""
    return Segment(type="file", data={"file_id": file_id, **extra})

Image(file_id, **extra)

图片消息段。

Source code in src/pylibob/segment.py
def Image(file_id: str, **extra: Any) -> Segment:
    """图片消息段。"""
    return Segment(type="image", data={"file_id": file_id, **extra})

Location(latitude, longitude, title, content, **extra)

位置消息段。

Source code in src/pylibob/segment.py
def Location(
    latitude: float,
    longitude: float,
    title: str,
    content: str,
    **extra: Any,
) -> Segment:
    """位置消息段。"""
    return Segment(
        type="location",
        data={
            "latitude": latitude,
            "longitude": longitude,
            "title": title,
            "content": content,
            **extra,
        },
    )

Mention(user_id, **extra)

提及(即 @)消息段。

Source code in src/pylibob/segment.py
def Mention(user_id: str, **extra: Any) -> Segment:
    """提及(即 @)消息段。"""
    return Segment(type="mention", data={"user_id": user_id, **extra})

MentionAll(**extra)

提及所有人消息段。

Source code in src/pylibob/segment.py
def MentionAll(**extra: Any) -> Segment:
    """提及所有人消息段。"""
    return Segment(type="mention_all", data=extra)

Reply(message_id, user_id, **extra)

回复消息段。

Source code in src/pylibob/segment.py
def Reply(message_id: str, user_id: str, **extra: Any) -> Segment:
    """回复消息段。"""
    return Segment(
        type="reply",
        data={"message_id": message_id, "user_id": user_id, **extra},
    )

Text(text, **extra)

纯文本消息段。

Source code in src/pylibob/segment.py
def Text(text: str, **extra: Any) -> Segment:
    """纯文本消息段。"""
    return Segment(type="text", data={"text": text, **extra})

Video(file_id, **extra)

视频消息段。

Source code in src/pylibob/segment.py
def Video(file_id: str, **extra: Any) -> Segment:
    """视频消息段。"""
    return Segment(type="video", data={"file_id": file_id, **extra})

Voice(file_id, **extra)

语音消息段。

Source code in src/pylibob/segment.py
def Voice(file_id: str, **extra: Any) -> Segment:
    """语音消息段。"""
    return Segment(type="voice", data={"file_id": file_id, **extra})