ErisPulse-OneBot11Adapter 4.1.0__tar.gz → 4.1.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.
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/PKG-INFO +171 -87
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/Core.py +123 -39
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/PKG-INFO +171 -87
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/README.md +170 -86
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/pyproject.toml +1 -1
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/SOURCES.txt +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/dependency_links.txt +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/entry_points.txt +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/requires.txt +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/top_level.txt +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/LICENSE +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/Converter.py +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/__init__.py +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/setup.cfg +0 -0
- {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.2}/test/test.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ErisPulse-OneBot11Adapter
|
|
3
|
-
Version: 4.1.
|
|
3
|
+
Version: 4.1.2
|
|
4
4
|
Summary: ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器
|
|
5
5
|
Author-email: wsu2059q <wsu2059@qq.com>
|
|
6
6
|
License: MIT License
|
|
@@ -146,6 +146,97 @@ await onebot.Send.To("user", 123456).Edit(123456789, "修改后的内容")
|
|
|
146
146
|
await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012", "345678"], "批量消息")
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
+
#### 群组管理:踢人
|
|
150
|
+
```python
|
|
151
|
+
await onebot.Send.To("group", 123456).Kick(789012)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### 群组管理:禁言
|
|
155
|
+
```python
|
|
156
|
+
await onebot.Send.To("group", 123456).Ban(789012, duration=1800) # 禁言30分钟
|
|
157
|
+
await onebot.Send.To("group", 123456).Ban(789012, duration=0) # 解除禁言
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### 群组管理:全体禁言
|
|
161
|
+
```python
|
|
162
|
+
await onebot.Send.To("group", 123456).WholeBan(enable=True)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### 群组管理:设置管理员
|
|
166
|
+
```python
|
|
167
|
+
await onebot.Send.To("group", 123456).SetAdmin(789012, enable=True)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### 群组管理:设置群名片
|
|
171
|
+
```python
|
|
172
|
+
await onebot.Send.To("group", 123456).SetCard(789012, "新名片")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### 群组管理:设置群名称
|
|
176
|
+
```python
|
|
177
|
+
await onebot.Send.To("group", 123456).SetGroupName("新群名")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### 群组管理:退群
|
|
181
|
+
```python
|
|
182
|
+
await onebot.Send.To("group", 123456).Leave()
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### 群组管理:设置头衔
|
|
186
|
+
```python
|
|
187
|
+
await onebot.Send.To("group", 123456).SetTitle(789012, "专属头衔")
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### 群组管理:设置群头像
|
|
191
|
+
```python
|
|
192
|
+
await onebot.Send.To("group", 123456).SetPortrait("http://example.com/avatar.jpg")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### 获取消息
|
|
196
|
+
```python
|
|
197
|
+
await onebot.Send.GetMsg(123456789)
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### 获取登录信息
|
|
201
|
+
```python
|
|
202
|
+
await onebot.Send.GetLoginInfo()
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### 获取好友列表
|
|
206
|
+
```python
|
|
207
|
+
await onebot.Send.GetFriendList()
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### 获取群信息
|
|
211
|
+
```python
|
|
212
|
+
await onebot.Send.To("group", 123456).GetGroupInfo()
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### 获取群列表
|
|
216
|
+
```python
|
|
217
|
+
await onebot.Send.GetGroupList()
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
#### 获取群成员信息
|
|
221
|
+
```python
|
|
222
|
+
await onebot.Send.To("group", 123456).GetGroupMemberInfo(789012)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### 获取群成员列表
|
|
226
|
+
```python
|
|
227
|
+
await onebot.Send.To("group", 123456).GetGroupMemberList()
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### 发送文件
|
|
231
|
+
```python
|
|
232
|
+
await onebot.Send.To("user", 123456).File("http://example.com/file.pdf")
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### 点赞
|
|
236
|
+
```python
|
|
237
|
+
await onebot.Send.To("user", 123456).Like(789012, times=10)
|
|
238
|
+
```
|
|
239
|
+
|
|
149
240
|
---
|
|
150
241
|
|
|
151
242
|
## 支持的消息类型及对应方法
|
|
@@ -171,6 +262,25 @@ await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012"
|
|
|
171
262
|
| `.Recall(message_id: Union[str, int])` | 撤回指定消息 | 消息管理 |
|
|
172
263
|
| `.Edit(message_id: Union[str, int], new_text: str)` | 编辑消息(撤回+重发) | 消息管理 |
|
|
173
264
|
| `.Batch(target_ids: List[str], text: str)` | 批量发送消息 | 群发功能 |
|
|
265
|
+
| `.File(file: Union[str, bytes], filename: str = "file.dat")` | 发送文件 | 文件传输 |
|
|
266
|
+
| `.Like(user_id: Union[str, int], times: int = 1)` | 发送好友赞 | 互动功能 |
|
|
267
|
+
| `.Kick(user_id: Union[str, int], reject_add_request: bool = False)` | 移除群成员 | 群组管理 |
|
|
268
|
+
| `.Ban(user_id: Union[str, int], duration: int = 1800)` | 群组禁言 | 群组管理 |
|
|
269
|
+
| `.WholeBan(enable: bool = True)` | 全体禁言 | 群组管理 |
|
|
270
|
+
| `.SetAdmin(user_id: Union[str, int], enable: bool = True)` | 设置管理员 | 群组管理 |
|
|
271
|
+
| `.SetCard(user_id: Union[str, int], card: str = "")` | 设置群名片 | 群组管理 |
|
|
272
|
+
| `.SetGroupName(name: str)` | 设置群名称 | 群组管理 |
|
|
273
|
+
| `.Leave(is_dismiss: bool = False)` | 退群/解散群 | 群组管理 |
|
|
274
|
+
| `.SetTitle(user_id: Union[str, int], title: str = "")` | 设置群头衔 | 群组管理 |
|
|
275
|
+
| `.SetPortrait(file: Union[str, bytes])` | 设置群头像 | 群组管理 |
|
|
276
|
+
| `.GetMsg(message_id: Union[str, int])` | 获取消息内容 | API |
|
|
277
|
+
| `.GetForwardMsg(id: Union[str, int])` | 获取合并转发消息 | API |
|
|
278
|
+
| `.GetLoginInfo()` | 获取登录号信息 | API |
|
|
279
|
+
| `.GetFriendList()` | 获取好友列表 | API |
|
|
280
|
+
| `.GetGroupInfo()` | 获取群信息(需To) | API |
|
|
281
|
+
| `.GetGroupList()` | 获取群列表 | API |
|
|
282
|
+
| `.GetGroupMemberInfo(user_id: Union[str, int])` | 获取群成员信息(需To) | API |
|
|
283
|
+
| `.GetGroupMemberList()` | 获取群成员列表(需To) | API |
|
|
174
284
|
|
|
175
285
|
---
|
|
176
286
|
|
|
@@ -178,76 +288,45 @@ await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012"
|
|
|
178
288
|
|
|
179
289
|
### 多账户配置
|
|
180
290
|
|
|
181
|
-
OneBot11
|
|
291
|
+
OneBot11适配器支持多账户配置,每个 Bot 独立配置:
|
|
182
292
|
|
|
183
293
|
```toml
|
|
184
|
-
#
|
|
185
|
-
[
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
294
|
+
# 主账户(Server 模式,被动接收连接)
|
|
295
|
+
[OneBotAdapter.bots.main]
|
|
296
|
+
bot_id = "123456789" # 机器人QQ号(必填)
|
|
297
|
+
mode = "server" # server 或 client
|
|
298
|
+
server_path = "/onebot" # WebSocket 路径
|
|
299
|
+
token = "your_token_here" # 认证Token
|
|
189
300
|
enabled = true
|
|
190
301
|
|
|
191
|
-
#
|
|
192
|
-
[
|
|
302
|
+
# 备用账户(Client 模式,主动连接)
|
|
303
|
+
[OneBotAdapter.bots.backup]
|
|
304
|
+
bot_id = "987654321"
|
|
193
305
|
mode = "client"
|
|
194
|
-
|
|
195
|
-
|
|
306
|
+
url = "ws://127.0.0.1:3002" # 主动连接的WS地址
|
|
307
|
+
token = "backup_token_here"
|
|
196
308
|
enabled = true
|
|
197
309
|
|
|
198
|
-
#
|
|
199
|
-
[
|
|
310
|
+
# 测试账户(禁用状态)
|
|
311
|
+
[OneBotAdapter.bots.test]
|
|
312
|
+
bot_id = "111111111"
|
|
200
313
|
mode = "client"
|
|
201
|
-
|
|
202
|
-
enabled = false
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### 默认账户配置
|
|
206
|
-
|
|
207
|
-
如果没有配置文件,适配器会自动创建默认配置:
|
|
208
|
-
|
|
209
|
-
```toml
|
|
210
|
-
[OneBotv11_Adapter.accounts.default]
|
|
211
|
-
mode = "server"
|
|
212
|
-
server_path = "/"
|
|
213
|
-
server_token = ""
|
|
214
|
-
client_url = "ws://127.0.0.1:3001"
|
|
215
|
-
client_token = ""
|
|
216
|
-
enabled = true
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### 旧配置兼容性
|
|
220
|
-
|
|
221
|
-
```toml
|
|
222
|
-
# 旧配置(仍支持,会显示迁移提醒)
|
|
223
|
-
[OneBotv11_Adapter]
|
|
224
|
-
mode = "server"
|
|
225
|
-
|
|
226
|
-
[OneBotv11_Adapter.server]
|
|
227
|
-
path = "/"
|
|
228
|
-
token = ""
|
|
229
|
-
|
|
230
|
-
[OneBotv11_Adapter.client]
|
|
231
|
-
url = "ws://127.0.0.1:3001"
|
|
232
|
-
token = ""
|
|
314
|
+
url = "ws://127.0.0.1:3003"
|
|
315
|
+
enabled = false
|
|
233
316
|
```
|
|
234
317
|
|
|
235
318
|
### 配置项说明
|
|
236
319
|
|
|
237
320
|
每个账户独立配置以下选项:
|
|
238
321
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
- 重连间隔:30秒
|
|
249
|
-
- API调用超时:30秒
|
|
250
|
-
- 最大重试次数:3次
|
|
322
|
+
| 配置项 | 类型 | 必填 | 说明 |
|
|
323
|
+
|--------|------|------|------|
|
|
324
|
+
| `bot_id` | string | 是 | 机器人QQ号 |
|
|
325
|
+
| `mode` | string | 否 | 运行模式:"server"(被动) 或 "client"(主动),默认 "server" |
|
|
326
|
+
| `token` | string | 否 | 认证Token(Server模式验证客户端 / Client模式发送认证头) |
|
|
327
|
+
| `server_path` | string | 否 | Server模式下WebSocket路径,默认 "/" |
|
|
328
|
+
| `url` | string | 否 | Client模式下要连接的WebSocket地址,默认 "ws://127.0.0.1:3001" |
|
|
329
|
+
| `enabled` | bool | 否 | 是否启用该账户,默认 true |
|
|
251
330
|
|
|
252
331
|
---
|
|
253
332
|
|
|
@@ -256,39 +335,45 @@ token = ""
|
|
|
256
335
|
### 多账户消息发送
|
|
257
336
|
|
|
258
337
|
```python
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
338
|
+
from ErisPulse.Core import adapter
|
|
339
|
+
onebot = adapter.get("onebot11")
|
|
340
|
+
|
|
341
|
+
# 使用账户名指定 Bot
|
|
342
|
+
await onebot.Send.Using("main").To("group", 123456).Text("来自主账户的消息")
|
|
343
|
+
|
|
344
|
+
# 使用 bot_id 指定 Bot
|
|
345
|
+
await onebot.Send.Using("987654321").To("group", 123456).Text("来自备用Bot的消息")
|
|
262
346
|
|
|
263
|
-
#
|
|
347
|
+
# 不指定时使用第一个启用的账户
|
|
264
348
|
await onebot.Send.To("group", 123456).Text("来自默认账户的消息")
|
|
265
349
|
```
|
|
266
350
|
|
|
267
|
-
该方法会自动处理响应结果并返回,若超时将抛出异常。
|
|
268
|
-
|
|
269
351
|
---
|
|
270
352
|
|
|
271
353
|
## 事件处理
|
|
272
354
|
|
|
273
|
-
|
|
355
|
+
推荐使用标准 Event 模块装饰器监听事件:
|
|
274
356
|
|
|
275
357
|
```python
|
|
276
|
-
|
|
277
|
-
@sdk.adapter.OneBot.on("message")
|
|
278
|
-
async def handle_message(event):
|
|
279
|
-
pass
|
|
358
|
+
from ErisPulse.Core.Event import message, notice, request
|
|
280
359
|
|
|
281
|
-
|
|
282
|
-
@sdk.adapter.OneBot.on("message")
|
|
360
|
+
@message.on_message()
|
|
283
361
|
async def handle_message(event):
|
|
284
|
-
|
|
362
|
+
if event.get_platform() == "onebot11":
|
|
363
|
+
await event.reply(f"收到消息: {event.get_text()}")
|
|
364
|
+
|
|
365
|
+
@notice.on_notice()
|
|
366
|
+
async def handle_notice(event):
|
|
367
|
+
if event.get_platform() == "onebot11":
|
|
368
|
+
if event.get("detail_type") == "group_member_increase":
|
|
369
|
+
await event.reply(f"欢迎新成员!")
|
|
370
|
+
|
|
371
|
+
@request.on_friend_request()
|
|
372
|
+
async def handle_friend_request(event):
|
|
373
|
+
await event.reply("好友请求已收到")
|
|
285
374
|
```
|
|
286
375
|
|
|
287
|
-
|
|
288
|
-
- `message`: 消息事件
|
|
289
|
-
- `notice`: 通知事件
|
|
290
|
-
- `request`: 请求事件
|
|
291
|
-
- `meta_event`: 元事件
|
|
376
|
+
支持的事件类型:`message`、`notice`、`request`、`meta_event`。
|
|
292
377
|
|
|
293
378
|
---
|
|
294
379
|
|
|
@@ -296,17 +381,15 @@ async def handle_message(event):
|
|
|
296
381
|
|
|
297
382
|
### 多账户运行模式
|
|
298
383
|
|
|
299
|
-
OneBot11适配器支持同时运行多个账户,每个账户可以独立配置为Server或Client模式:
|
|
384
|
+
OneBot11适配器支持同时运行多个账户,每个账户可以独立配置为 Server 或 Client 模式:
|
|
300
385
|
|
|
301
386
|
```python
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
print(f"已配置账户: {list(accounts.keys())}")
|
|
387
|
+
from ErisPulse.Core import adapter
|
|
388
|
+
onebot = adapter.get("onebot11")
|
|
305
389
|
|
|
306
|
-
#
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
print(f"主账户模式: {main_account.mode}, 启用状态: {main_account.enabled}")
|
|
390
|
+
# 查看所有账户
|
|
391
|
+
for name, account in onebot.accounts.items():
|
|
392
|
+
print(f"{name}: bot_id={account.bot_id}, mode={account.mode}, enabled={account.enabled}")
|
|
310
393
|
```
|
|
311
394
|
|
|
312
395
|
### Server 模式(作为服务端监听连接)
|
|
@@ -325,8 +408,10 @@ if "test" in accounts:
|
|
|
325
408
|
|
|
326
409
|
## 注意事项
|
|
327
410
|
|
|
328
|
-
1. 生产环境建议启用 Token
|
|
329
|
-
2.
|
|
411
|
+
1. 生产环境建议启用 Token 认证以保证安全性
|
|
412
|
+
2. 二进制内容(图片、语音等)支持 `str`(URL/路径) 和 `bytes` 传入
|
|
413
|
+
3. Server 模式下无需公网IP,Client 模式需 OneBot 服务端可被连接
|
|
414
|
+
4. 每个 Server 模式账户会注册独立的 WebSocket 路由路径
|
|
330
415
|
|
|
331
416
|
---
|
|
332
417
|
|
|
@@ -334,5 +419,4 @@ if "test" in accounts:
|
|
|
334
419
|
|
|
335
420
|
- [ErisPulse 主库](https://github.com/ErisPulse/ErisPulse/)
|
|
336
421
|
- [OneBot V11 协议文档](https://github.com/botuniverse/onebot-11)
|
|
337
|
-
- [go-cqhttp 项目地址](https://github.com/Mrs4s/go-cqhttp)
|
|
338
422
|
- [模块开发指南](https://github.com/ErisPulse/ErisPulse/tree/main/docs/DEVELOPMENT.md)
|