ErisPulse-OneBot12Adapter 1.2.0__tar.gz → 4.0.1__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.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: ErisPulse-OneBot12Adapter
3
+ Version: 4.0.1
4
+ Summary: ErisPulse的OneBotV12协议适配模块,基线协议适配器
5
+ Author-email: wsu2059q <wsu2059@qq.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 WSu2059
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: homepage, https://github.com/ErisPulse/ErisPulse-OneBot12Adapter
29
+ Keywords: erispulse,erispulse-adapter
30
+ Requires-Python: >=3.10
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ Dynamic: license-file
34
+
35
+ # ErisPulse OneBot12 适配器
36
+
37
+ 基于 [ErisPulse](https://github.com/ErisPulse/ErisPulse/) 框架的 OneBot V12 基线协议适配器,支持多账号、Server/Client 双模式运行。
38
+
39
+ ## 安装
40
+
41
+ ```bash
42
+ epsdk install OneBot12Adapter
43
+ ```
44
+
45
+ ## 配置
46
+
47
+ 在 `config/config.toml` 中添加:
48
+
49
+ ```toml
50
+ [OneBotv12_Adapter.accounts.main]
51
+ bot_id = "机器人ID"
52
+ mode = "server"
53
+ server_path = "/onebot12"
54
+ server_token = ""
55
+ enabled = true
56
+
57
+ # Client 模式示例
58
+ [OneBotv12_Adapter.accounts.backup]
59
+ bot_id = "另一个机器人ID"
60
+ mode = "client"
61
+ client_url = "ws://127.0.0.1:3002"
62
+ client_token = ""
63
+ enabled = true
64
+ ```
65
+
66
+ ### 配置字段
67
+
68
+ | 字段 | 类型 | 必填 | 说明 |
69
+ |------|------|------|------|
70
+ | `bot_id` | string | 是 | 机器人ID,用于SDK路由 |
71
+ | `mode` | string | 否 | 运行模式:`server`(被动)或 `client`(主动),默认 `server` |
72
+ | `server_path` | string | 否 | Server 模式 WS 路径,默认 `/onebot12` |
73
+ | `server_token` | string | 否 | Server 模式认证 Token |
74
+ | `client_url` | string | 否 | Client 模式 WS 地址,默认 `ws://127.0.0.1:3001` |
75
+ | `client_token` | string | 否 | Client 模式认证 Token |
76
+ | `enabled` | bool | 否 | 是否启用(默认 true) |
77
+ | `platform` | string | 否 | 平台标识,默认 `onebot12` |
78
+ | `implementation` | string | 否 | 实现标识(如 `go-cqhttp`) |
79
+
80
+ ## 快速开始
81
+
82
+ ```python
83
+ from ErisPulse import sdk
84
+ from ErisPulse.Core.Event import command, message
85
+
86
+ @command("hello")
87
+ async def hello_handler(event):
88
+ await event.reply("Hello from OneBot12!")
89
+
90
+ async def main():
91
+ await sdk.run(keep_running=True)
92
+
93
+ if __name__ == "__main__":
94
+ import asyncio
95
+ asyncio.run(main())
96
+ ```
97
+
98
+ ## 消息发送
99
+
100
+ ```python
101
+ onebot12 = sdk.adapter.get("onebot12")
102
+
103
+ # 文本消息
104
+ await onebot12.Send.To("user", "123456").Text("Hello!")
105
+ await onebot12.Send.To("group", "789012").Text("群消息")
106
+
107
+ # 媒体消息
108
+ await onebot12.Send.To("user", "123456").Image("file_id_or_url")
109
+ await onebot12.Send.To("user", "123456").Video("file_id_or_url")
110
+ await onebot12.Send.To("user", "123456").Audio("file_id_or_url")
111
+
112
+ # 发送 bytes
113
+ with open("image.png", "rb") as f:
114
+ await onebot12.Send.To("user", "123456").Image(f.read())
115
+
116
+ # 位置
117
+ await onebot12.Send.To("group", "789012").Location(39.9042, 116.4074, title="北京")
118
+ ```
119
+
120
+ ### 链式修饰
121
+
122
+ ```python
123
+ # @用户
124
+ await onebot12.Send.To("group", "789012").At("123456").Text("你好!")
125
+
126
+ # @全体
127
+ await onebot12.Send.To("group", "789012").AtAll().Text("通知!")
128
+
129
+ # 回复消息
130
+ await onebot12.Send.To("group", "789012").Reply("msg_id").Text("回复内容")
131
+
132
+ # 组合使用
133
+ await onebot12.Send.To("group", "789012").Reply("msg_id").At("123456").Text("回复并@")
134
+ ```
135
+
136
+ ### 指定账户发送
137
+
138
+ ```python
139
+ # 使用 Using 指定账户
140
+ await onebot12.Send.Using("backup").To("user", "123456").Text("来自备用账户")
141
+ ```
142
+
143
+ ### 消息操作
144
+
145
+ ```python
146
+ # 撤回
147
+ await onebot12.Send.To("group", "789012").Recall("message_id")
148
+
149
+ # 编辑
150
+ await onebot12.Send.To("group", "789012").Edit("message_id", "新内容")
151
+
152
+ # 原始 OB12 消息段
153
+ await onebot12.Send.To("group", "789012").Raw_ob12([
154
+ {"type": "text", "data": {"text": "你好"}},
155
+ {"type": "image", "data": {"file_id": "xxx"}}
156
+ ])
157
+ ```
158
+
159
+ ## 运行模式
160
+
161
+ ### Server 模式(默认)
162
+
163
+ 启动 WS 服务器等待 OneBot12 实现端连接。适用于多客户端连接同一服务端的场景。
164
+
165
+ ### Client 模式
166
+
167
+ 主动连接 OneBot12 实现端。支持自动重连(间隔 30 秒)。
168
+
169
+ ## 事件处理
170
+
171
+ OneBot12 适配器直接 pass-through 标准格式事件,无需转换。使用 ErisPulse 标准事件处理器:
172
+
173
+ ```python
174
+ from ErisPulse.Core.Event import message, notice, request, meta
175
+
176
+ @message.on_message()
177
+ async def handle_message(event):
178
+ text = event.get_text()
179
+ user_id = event.get_user_id()
180
+ group_id = event.get_group_id()
181
+ await event.reply(f"收到: {text}")
182
+
183
+ @notice.on_group_increase()
184
+ async def handle_member_increase(event):
185
+ group_id = event.get_group_id()
186
+ user_id = event.get_user_id()
187
+ await event.reply(f"欢迎 {user_id} 加入群!")
188
+
189
+ @request.on_friend_request()
190
+ async def handle_friend_request(event):
191
+ user_id = event.get_user_id()
192
+ comment = event.get_comment()
193
+ ```
194
+
195
+ ### 事件扩展字段
196
+
197
+ 所有事件自动添加 `onebot12_raw_type` 字段保留原始事件类型。
198
+
199
+ ## API 调用
200
+
201
+ ```python
202
+ # 直接 API 调用
203
+ resp = await onebot12.call_api(
204
+ "get_user_info",
205
+ _account_id="main",
206
+ user_id="123456"
207
+ )
208
+
209
+ # 获取自身信息
210
+ info = await onebot12.call_api("get_self_info", _account_id="main")
211
+ ```
212
+
213
+ ### 响应格式
214
+
215
+ ```python
216
+ # 成功
217
+ {"status": "ok", "retcode": 0, "data": {...}, "message_id": "xxx", "message": ""}
218
+
219
+ # 失败
220
+ {"status": "failed", "retcode": 10003, "data": None, "message_id": "", "message": "错误描述"}
221
+ ```
222
+
223
+ ## 参考链接
224
+
225
+ - [ErisPulse 主库](https://github.com/ErisPulse/ErisPulse/)
226
+ - [OneBot V12 协议文档](https://12.onebot.dev/)