onebot-protocol 0.0.2__tar.gz
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.
- onebot_protocol-0.0.2/.gitignore +1 -0
- onebot_protocol-0.0.2/PKG-INFO +11 -0
- onebot_protocol-0.0.2/README.md +1 -0
- onebot_protocol-0.0.2/onebot_protocol/__init__.py +27 -0
- onebot_protocol-0.0.2/onebot_protocol/models.py +110 -0
- onebot_protocol-0.0.2/publish.py +60 -0
- onebot_protocol-0.0.2/pyproject.toml +20 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: onebot-protocol
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: OneBot 通信协议,定义消息收发的公共数据结构
|
|
5
|
+
Project-URL: Repository, https://github.com/XiaoHui2023/onebot-protocol
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: pydantic>=2.0
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# onebot-protocol
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# onebot-protocol
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from .models import (
|
|
2
|
+
MessagePayload,
|
|
3
|
+
MessageSegment,
|
|
4
|
+
TextMessageSegment,
|
|
5
|
+
MentionMessageSegment,
|
|
6
|
+
MentionAllMessageSegment,
|
|
7
|
+
ImageMessageSegment,
|
|
8
|
+
VoiceMessageSegment,
|
|
9
|
+
AudioMessageSegment,
|
|
10
|
+
VideoMessageSegment,
|
|
11
|
+
FileMessageSegment,
|
|
12
|
+
LocationMessageSegment,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"MessagePayload",
|
|
17
|
+
"MessageSegment",
|
|
18
|
+
"TextMessageSegment",
|
|
19
|
+
"MentionMessageSegment",
|
|
20
|
+
"MentionAllMessageSegment",
|
|
21
|
+
"ImageMessageSegment",
|
|
22
|
+
"VoiceMessageSegment",
|
|
23
|
+
"AudioMessageSegment",
|
|
24
|
+
"VideoMessageSegment",
|
|
25
|
+
"FileMessageSegment",
|
|
26
|
+
"LocationMessageSegment",
|
|
27
|
+
]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field
|
|
2
|
+
from typing import Literal, List, Annotated, Union
|
|
3
|
+
|
|
4
|
+
class TextSegmentData(BaseModel):
|
|
5
|
+
"""纯文本"""
|
|
6
|
+
text: str
|
|
7
|
+
|
|
8
|
+
class MentionSegmentData(BaseModel):
|
|
9
|
+
"""@某人"""
|
|
10
|
+
user_id: str
|
|
11
|
+
|
|
12
|
+
class MentionAllSegmentData(BaseModel):
|
|
13
|
+
"""@所有人"""
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
class ImageSegmentData(BaseModel):
|
|
17
|
+
"""图片"""
|
|
18
|
+
file_id: str
|
|
19
|
+
|
|
20
|
+
class VoiceSegmentData(BaseModel):
|
|
21
|
+
"""语音"""
|
|
22
|
+
file_id: str
|
|
23
|
+
|
|
24
|
+
class AudioSegmentData(BaseModel):
|
|
25
|
+
"""音频"""
|
|
26
|
+
file_id: str
|
|
27
|
+
|
|
28
|
+
class VideoSegmentData(BaseModel):
|
|
29
|
+
"""视频"""
|
|
30
|
+
file_id: str
|
|
31
|
+
|
|
32
|
+
class FileSegmentData(BaseModel):
|
|
33
|
+
"""文件"""
|
|
34
|
+
file_id: str
|
|
35
|
+
|
|
36
|
+
class LocationSegmentData(BaseModel):
|
|
37
|
+
"""位置"""
|
|
38
|
+
latitude: float
|
|
39
|
+
longitude: float
|
|
40
|
+
title: str
|
|
41
|
+
content: str
|
|
42
|
+
|
|
43
|
+
class ReplySegmentData(BaseModel):
|
|
44
|
+
"""回复"""
|
|
45
|
+
message_id: str
|
|
46
|
+
user_id: str | None = None # 可选
|
|
47
|
+
|
|
48
|
+
class TextMessageSegment(BaseModel):
|
|
49
|
+
type: Literal["text"] = "text"
|
|
50
|
+
data: TextSegmentData
|
|
51
|
+
|
|
52
|
+
class MentionMessageSegment(BaseModel):
|
|
53
|
+
type: Literal["mention"] = "mention"
|
|
54
|
+
data: MentionSegmentData
|
|
55
|
+
|
|
56
|
+
class MentionAllMessageSegment(BaseModel):
|
|
57
|
+
type: Literal["mention_all"] = "mention_all"
|
|
58
|
+
data: MentionAllSegmentData = Field(default_factory=MentionAllSegmentData)
|
|
59
|
+
|
|
60
|
+
class ImageMessageSegment(BaseModel):
|
|
61
|
+
type: Literal["image"] = "image"
|
|
62
|
+
data: ImageSegmentData
|
|
63
|
+
|
|
64
|
+
class VoiceMessageSegment(BaseModel):
|
|
65
|
+
type: Literal["voice"] = "voice"
|
|
66
|
+
data: VoiceSegmentData
|
|
67
|
+
|
|
68
|
+
class AudioMessageSegment(BaseModel):
|
|
69
|
+
type: Literal["audio"] = "audio"
|
|
70
|
+
data: AudioSegmentData
|
|
71
|
+
|
|
72
|
+
class VideoMessageSegment(BaseModel):
|
|
73
|
+
type: Literal["video"] = "video"
|
|
74
|
+
data: VideoSegmentData
|
|
75
|
+
|
|
76
|
+
class FileMessageSegment(BaseModel):
|
|
77
|
+
type: Literal["file"] = "file"
|
|
78
|
+
data: FileSegmentData
|
|
79
|
+
|
|
80
|
+
class LocationMessageSegment(BaseModel):
|
|
81
|
+
type: Literal["location"] = "location"
|
|
82
|
+
data: LocationSegmentData
|
|
83
|
+
|
|
84
|
+
class ReplyMessageSegment(BaseModel):
|
|
85
|
+
type: Literal["reply"] = "reply"
|
|
86
|
+
data: ReplySegmentData
|
|
87
|
+
|
|
88
|
+
MessageSegment = Annotated[
|
|
89
|
+
Union[
|
|
90
|
+
TextMessageSegment,
|
|
91
|
+
MentionMessageSegment,
|
|
92
|
+
MentionAllMessageSegment,
|
|
93
|
+
ImageMessageSegment,
|
|
94
|
+
VoiceMessageSegment,
|
|
95
|
+
AudioMessageSegment,
|
|
96
|
+
VideoMessageSegment,
|
|
97
|
+
FileMessageSegment,
|
|
98
|
+
LocationMessageSegment,
|
|
99
|
+
ReplyMessageSegment,
|
|
100
|
+
],
|
|
101
|
+
Field(discriminator="type"),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
class MessagePayload(BaseModel):
|
|
105
|
+
"""消息载体"""
|
|
106
|
+
source_type: Literal['group', 'private'] = Field(..., description="消息来源类型")
|
|
107
|
+
session_id: str = Field(..., description="会话 ID")
|
|
108
|
+
bot_id: str = Field(..., description="机器人 ID")
|
|
109
|
+
user_id: str = Field(..., description="用户 ID")
|
|
110
|
+
messages: List[MessageSegment] = Field(..., description="消息列表")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyPI 一键发布脚本
|
|
3
|
+
自动递增补丁版本号并发布到 PyPI
|
|
4
|
+
用法: python publish.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import re
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import shutil
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
14
|
+
PYPROJECT = SCRIPT_DIR / "pyproject.toml"
|
|
15
|
+
DIST_DIR = SCRIPT_DIR / "dist"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def run(cmd: str):
|
|
19
|
+
print(f"\n>>> {cmd}")
|
|
20
|
+
result = subprocess.run(cmd, shell=True, cwd=SCRIPT_DIR)
|
|
21
|
+
if result.returncode != 0:
|
|
22
|
+
print(f"\n命令失败 (exit code: {result.returncode})")
|
|
23
|
+
sys.exit(result.returncode)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def bump_version() -> str:
|
|
27
|
+
content = PYPROJECT.read_text(encoding="utf-8")
|
|
28
|
+
match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE)
|
|
29
|
+
if not match:
|
|
30
|
+
print("无法在 pyproject.toml 中找到版本号")
|
|
31
|
+
sys.exit(1)
|
|
32
|
+
|
|
33
|
+
major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3))
|
|
34
|
+
old_version = f"{major}.{minor}.{patch}"
|
|
35
|
+
new_version = f"{major}.{minor}.{patch + 1}"
|
|
36
|
+
|
|
37
|
+
new_content = content.replace(f'version = "{old_version}"', f'version = "{new_version}"')
|
|
38
|
+
PYPROJECT.write_text(new_content, encoding="utf-8")
|
|
39
|
+
return new_version
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
new_version = bump_version()
|
|
44
|
+
print(f"版本号已更新为: {new_version}")
|
|
45
|
+
|
|
46
|
+
if DIST_DIR.exists():
|
|
47
|
+
print(f"清理 {DIST_DIR} ...")
|
|
48
|
+
shutil.rmtree(DIST_DIR)
|
|
49
|
+
|
|
50
|
+
print("开始构建...")
|
|
51
|
+
run("python -m build")
|
|
52
|
+
|
|
53
|
+
print("上传到 PyPI...")
|
|
54
|
+
run("python -m twine upload dist/*")
|
|
55
|
+
|
|
56
|
+
print("\n发布完成!")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if __name__ == "__main__":
|
|
60
|
+
main()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "onebot-protocol"
|
|
7
|
+
version = "0.0.2"
|
|
8
|
+
description = "OneBot 通信协议,定义消息收发的公共数据结构"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pydantic>=2.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Repository = "https://github.com/XiaoHui2023/onebot-protocol"
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.wheel]
|
|
20
|
+
packages = ["onebot_protocol"]
|