python-library-onebot-protocol 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .models import (
|
|
2
|
+
AudioMessageSegment,
|
|
3
|
+
FileData,
|
|
4
|
+
FileMessageSegment,
|
|
5
|
+
ImageMessageSegment,
|
|
6
|
+
LocationMessageSegment,
|
|
7
|
+
MentionAllMessageSegment,
|
|
8
|
+
MentionMessageSegment,
|
|
9
|
+
MessagePayload,
|
|
10
|
+
MessageSegment,
|
|
11
|
+
ReplyMessageSegment,
|
|
12
|
+
TextMessageSegment,
|
|
13
|
+
TextSegmentData,
|
|
14
|
+
VideoMessageSegment,
|
|
15
|
+
VoiceMessageSegment,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"AudioMessageSegment",
|
|
20
|
+
"FileData",
|
|
21
|
+
"FileMessageSegment",
|
|
22
|
+
"ImageMessageSegment",
|
|
23
|
+
"LocationMessageSegment",
|
|
24
|
+
"MentionAllMessageSegment",
|
|
25
|
+
"MentionMessageSegment",
|
|
26
|
+
"MessagePayload",
|
|
27
|
+
"MessageSegment",
|
|
28
|
+
"ReplyMessageSegment",
|
|
29
|
+
"TextMessageSegment",
|
|
30
|
+
"TextSegmentData",
|
|
31
|
+
"VideoMessageSegment",
|
|
32
|
+
"VoiceMessageSegment",
|
|
33
|
+
]
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from typing import Annotated, Any, Literal, Union
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TextSegmentData(BaseModel):
|
|
8
|
+
text: str = Field(description="纯文本")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MentionSegmentData(BaseModel):
|
|
12
|
+
user_id: str = Field(description="被 @ 的用户 ID")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class MentionAllSegmentData(BaseModel):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FileData(BaseModel):
|
|
20
|
+
name: str | None = Field(default=None, description="显示用文件名")
|
|
21
|
+
content: str | None = Field(
|
|
22
|
+
default=None,
|
|
23
|
+
description="内容引用,如 URL、平台资源标识或 Base64 等,由实现方约定编码",
|
|
24
|
+
)
|
|
25
|
+
mime_type: str | None = Field(default=None, description="MIME 类型")
|
|
26
|
+
size: int | None = Field(default=None, description="字节大小")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ImageSegmentData(FileData):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class VoiceSegmentData(FileData):
|
|
34
|
+
pass
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class AudioSegmentData(FileData):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class VideoSegmentData(FileData):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class FileSegmentData(FileData):
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class LocationSegmentData(BaseModel):
|
|
50
|
+
latitude: float = Field(description="纬度")
|
|
51
|
+
longitude: float = Field(description="经度")
|
|
52
|
+
title: str = Field(description="位置标题")
|
|
53
|
+
content: str = Field(description="位置说明")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ReplySegmentData(BaseModel):
|
|
57
|
+
message_id: str = Field(description="被回复的消息 ID")
|
|
58
|
+
user_id: str | None = Field(default=None, description="被回复用户 ID")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class TextMessageSegment(BaseModel):
|
|
62
|
+
type: Literal["text"] = "text"
|
|
63
|
+
data: TextSegmentData
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class MentionMessageSegment(BaseModel):
|
|
67
|
+
type: Literal["mention"] = "mention"
|
|
68
|
+
data: MentionSegmentData
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class MentionAllMessageSegment(BaseModel):
|
|
72
|
+
type: Literal["mention_all"] = "mention_all"
|
|
73
|
+
data: MentionAllSegmentData = Field(default_factory=MentionAllSegmentData)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ImageMessageSegment(BaseModel):
|
|
77
|
+
type: Literal["image"] = "image"
|
|
78
|
+
data: ImageSegmentData
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class VoiceMessageSegment(BaseModel):
|
|
82
|
+
type: Literal["voice"] = "voice"
|
|
83
|
+
data: VoiceSegmentData
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class AudioMessageSegment(BaseModel):
|
|
87
|
+
type: Literal["audio"] = "audio"
|
|
88
|
+
data: AudioSegmentData
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class VideoMessageSegment(BaseModel):
|
|
92
|
+
type: Literal["video"] = "video"
|
|
93
|
+
data: VideoSegmentData
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class FileMessageSegment(BaseModel):
|
|
97
|
+
type: Literal["file"] = "file"
|
|
98
|
+
data: FileSegmentData
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class LocationMessageSegment(BaseModel):
|
|
102
|
+
type: Literal["location"] = "location"
|
|
103
|
+
data: LocationSegmentData
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ReplyMessageSegment(BaseModel):
|
|
107
|
+
type: Literal["reply"] = "reply"
|
|
108
|
+
data: ReplySegmentData
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
MessageSegment = Annotated[
|
|
112
|
+
Union[
|
|
113
|
+
TextMessageSegment,
|
|
114
|
+
MentionMessageSegment,
|
|
115
|
+
MentionAllMessageSegment,
|
|
116
|
+
ImageMessageSegment,
|
|
117
|
+
VoiceMessageSegment,
|
|
118
|
+
AudioMessageSegment,
|
|
119
|
+
VideoMessageSegment,
|
|
120
|
+
FileMessageSegment,
|
|
121
|
+
LocationMessageSegment,
|
|
122
|
+
ReplyMessageSegment,
|
|
123
|
+
],
|
|
124
|
+
Field(discriminator="type"),
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class MessagePayload(BaseModel):
|
|
129
|
+
message_id: str = Field(default="", description="消息唯一 ID")
|
|
130
|
+
source_type: Literal["group", "private"] = Field(description="会话类型")
|
|
131
|
+
session_id: str = Field(description="会话 ID")
|
|
132
|
+
bot_id: str = Field(default="", description="机器人 ID")
|
|
133
|
+
user_id: str | None = Field(default=None, description="发送方用户 ID")
|
|
134
|
+
messages: list[MessageSegment] = Field(description="消息段列表")
|
|
135
|
+
post_type: str = Field(default="", description="事件类型")
|
|
136
|
+
|
|
137
|
+
def model_post_init(self, __context: Any) -> None:
|
|
138
|
+
if not self.message_id:
|
|
139
|
+
self.message_id = str(uuid4())
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-library-onebot-protocol
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OneBot 风格消息载荷与消息段模型
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: pydantic<3,>=2.0
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# onebot-protocol
|
|
10
|
+
|
|
11
|
+
OneBot 通信协议,定义消息收发的公共数据结构。基于`OneBot 11`标准,使用 Pydantic 提供类型安全的模型定义。
|
|
12
|
+
|
|
13
|
+
## 特性
|
|
14
|
+
|
|
15
|
+
- 完整的消息段(Message Segment)类型:文本、提及、图片、语音、视频、文件、位置、回复等
|
|
16
|
+
- 图片、语音、音频、视频、文件段共用 `FileData`(`name`、`content`、`mime_type`、`size`)
|
|
17
|
+
- 支持 discriminated union,根据 `type` 字段自动解析消息类型
|
|
18
|
+
|
|
19
|
+
## 文件载荷 `FileData`
|
|
20
|
+
|
|
21
|
+
| 字段 | 说明 |
|
|
22
|
+
|------|------|
|
|
23
|
+
| `name` | 显示用文件名(可选) |
|
|
24
|
+
| `content` | 内容引用,如 URL、平台资源标识或 Base64 等(可选,编码由实现方约定) |
|
|
25
|
+
| `mime_type` | MIME 类型(可选) |
|
|
26
|
+
| `size` | 字节大小(可选) |
|
|
27
|
+
|
|
28
|
+
`image` / `voice` / `audio` / `video` / `file` 各段类型的 `data` 均为对应子类,字段与 `FileData` 相同。
|
|
29
|
+
|
|
30
|
+
## 支持的消息类型
|
|
31
|
+
|
|
32
|
+
| 类型 | 说明 |
|
|
33
|
+
|------|------|
|
|
34
|
+
| `text` | 纯文本 |
|
|
35
|
+
| `mention` | @某人 |
|
|
36
|
+
| `mention_all` | @所有人 |
|
|
37
|
+
| `image` | 图片 |
|
|
38
|
+
| `voice` | 语音 |
|
|
39
|
+
| `audio` | 音频 |
|
|
40
|
+
| `video` | 视频 |
|
|
41
|
+
| `file` | 文件 |
|
|
42
|
+
| `location` | 位置 |
|
|
43
|
+
| `reply` | 回复 |
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
onebot_protocol/__init__.py,sha256=N-TEoAkFXD0VX2Y2faz9l7apIpun8BQ6YQo4vQsxCtQ,766
|
|
2
|
+
onebot_protocol/models.py,sha256=3H7emeI___rXZM1Lu7a6At3SXYTkma5433y1q2sOddY,3713
|
|
3
|
+
python_library_onebot_protocol-0.1.0.dist-info/METADATA,sha256=FEYsDbTXQwlc-o5NbrWDtgaMZtWAmKisX8YvO-FAzC4,1423
|
|
4
|
+
python_library_onebot_protocol-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
5
|
+
python_library_onebot_protocol-0.1.0.dist-info/RECORD,,
|