ErisPulse-OneBot11Adapter 4.1.0__tar.gz → 4.1.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.
Files changed (15) hide show
  1. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/PKG-INFO +171 -87
  2. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/OneBotAdapter/Core.py +53 -35
  3. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/PKG-INFO +171 -87
  4. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/README.md +170 -86
  5. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/pyproject.toml +1 -1
  6. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/SOURCES.txt +0 -0
  7. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/dependency_links.txt +0 -0
  8. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/entry_points.txt +0 -0
  9. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/requires.txt +0 -0
  10. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/ErisPulse_OneBot11Adapter.egg-info/top_level.txt +0 -0
  11. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/LICENSE +0 -0
  12. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/OneBotAdapter/Converter.py +0 -0
  13. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/OneBotAdapter/__init__.py +0 -0
  14. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/setup.cfg +0 -0
  15. {erispulse_onebot11adapter-4.1.0 → erispulse_onebot11adapter-4.1.1}/test/test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot11Adapter
3
- Version: 4.1.0
3
+ Version: 4.1.1
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
- [OneBotv11_Adapter.accounts.main]
186
- mode = "server"
187
- server_path = "/onebot"
188
- server_token = "your_token_here"
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
- [OneBotv11_Adapter.accounts.backup]
302
+ # 备用账户(Client 模式,主动连接)
303
+ [OneBotAdapter.bots.backup]
304
+ bot_id = "987654321"
193
305
  mode = "client"
194
- client_url = "ws://127.0.0.1:3002"
195
- client_token = "backup_token_here"
306
+ url = "ws://127.0.0.1:3002" # 主动连接的WS地址
307
+ token = "backup_token_here"
196
308
  enabled = true
197
309
 
198
- # 测试账户配置
199
- [OneBotv11_Adapter.accounts.test]
310
+ # 测试账户(禁用状态)
311
+ [OneBotAdapter.bots.test]
312
+ bot_id = "111111111"
200
313
  mode = "client"
201
- client_url = "ws://127.0.0.1:3003"
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
- - `mode`: 运行模式,可选 "server"(服务端)或 "client"(客户端)
240
- - `server_path`: Server模式下的WebSocket路径
241
- - `server_token`: Server模式下的认证Token(可选)
242
- - `client_url`: Client模式下要连接的WebSocket地址
243
- - `client_token`: Client模式下的认证Token(可选)
244
- - `enabled`: 是否启用该账户(true/false)
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
- await onebot.Send.To("group", 123456).Account("main").Text("来自主账户的消息")
261
- await onebot.Send.To("group", 123456).Account("backup").Text("来自备用账户的消息")
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
- OneBot适配器支持两种方式监听事件:
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
- pass
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
- accounts = onebot.accounts
304
- print(f"已配置账户: {list(accounts.keys())}")
387
+ from ErisPulse.Core import adapter
388
+ onebot = adapter.get("onebot11")
305
389
 
306
- # 检查特定账户状态
307
- if "test" in accounts:
308
- main_account = accounts["test"]
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. 对于二进制内容(如图片、语音等),支持直接传入 bytes 数据。
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)
@@ -4,7 +4,7 @@ OneBot11 适配器核心模块
4
4
  实现 OneBot11 协议与 ErisPulse 框架的对接,支持 WebSocket Server/Client 混合运行模式
5
5
 
6
6
  {!--< tips >!--}
7
- 1. 支持多账户管理,每个账户有独立的 bot_id
7
+ 1. 支持多账户管理
8
8
  2. 支持 self_id → account_name 自动映射,event.reply() 无需关心账户配置
9
9
  3. 提供 WebSocket Server/Client 混合运行模式
10
10
  4. 完整的 DSL 消息发送和请求操作接口
@@ -32,14 +32,6 @@ class OneBotAccountConfig(BotAccountConfig):
32
32
  {!--< /tips >!--}
33
33
  """
34
34
 
35
- bot_id: str = field(
36
- default="",
37
- metadata={
38
- "description": "机器人ID/QQ号",
39
- "required": True,
40
- "webui": {"widget": "text", "group": "basic", "order": 1},
41
- },
42
- )
43
35
  mode: str = field(
44
36
  default="server",
45
37
  metadata={
@@ -708,6 +700,8 @@ class OneBotAdapter(BaseAdapter):
708
700
  """
709
701
  super().__init__(sdk_ref)
710
702
  self._self_id_map: Dict[str, str] = {}
703
+ self._bot_ids: Dict[str, str] = {}
704
+ self._pending_connect_meta: set = set()
711
705
  self.connections: Dict[str, Any] = {}
712
706
  self._api_response_futures: Dict[str, Dict[str, asyncio.Future]] = {}
713
707
  self.reconnect_tasks: Dict[str, asyncio.Task] = {}
@@ -732,6 +726,21 @@ class OneBotAdapter(BaseAdapter):
732
726
  """
733
727
  return "OneBotAdapter"
734
728
 
729
+ def _get_bot_id(self, account_name: str) -> str:
730
+ return self._bot_ids.get(account_name, "")
731
+
732
+ def _bot_id_display(self, account_name: str) -> str:
733
+ return self._bot_ids.get(account_name, "待确认")
734
+
735
+ def _update_bot_id(self, account_name: str, self_id: str):
736
+ old = self._bot_ids.get(account_name)
737
+ if not old:
738
+ self._bot_ids[account_name] = self_id
739
+ self.logger.info(f"账户 {account_name} 自动识别 bot_id: {self_id}")
740
+ elif old != self_id:
741
+ self._bot_ids[account_name] = self_id
742
+ self.logger.warning(f"账户 {account_name} bot_id 变更: {old} → {self_id}")
743
+
735
744
  def _register_event_methods(self):
736
745
  """
737
746
  注册 OneBot11 平台的事件扩展方法
@@ -807,7 +816,7 @@ class OneBotAdapter(BaseAdapter):
807
816
  await connection.send_text(json.dumps(payload))
808
817
  except Exception as e:
809
818
  self.logger.error(
810
- f"账户 {account_name} (bot_id: {account.bot_id}) 发送请求失败: {str(e)}"
819
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 发送请求失败: {str(e)}"
811
820
  )
812
821
  if echo in self._api_response_futures[account_name]:
813
822
  del self._api_response_futures[account_name][echo]
@@ -815,13 +824,13 @@ class OneBotAdapter(BaseAdapter):
815
824
 
816
825
  try:
817
826
  self.logger.debug(
818
- f"账户 {account_name} (bot_id: {account.bot_id}) 请求: {payload}"
827
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 请求: {payload}"
819
828
  )
820
829
 
821
830
  raw_response = await asyncio.wait_for(future, timeout=self.default_timeout)
822
831
 
823
832
  self.logger.debug(
824
- f"账户 {account_name} (bot_id: {account.bot_id}) 响应: {raw_response}"
833
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 响应: {raw_response}"
825
834
  )
826
835
 
827
836
  message_id = ""
@@ -842,14 +851,14 @@ class OneBotAdapter(BaseAdapter):
842
851
 
843
852
  except asyncio.TimeoutError:
844
853
  self.logger.error(
845
- f"账户 {account_name} (bot_id: {account.bot_id}) API调用超时: {endpoint}"
854
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) API调用超时: {endpoint}"
846
855
  )
847
856
  if not future.done():
848
857
  future.cancel()
849
858
 
850
859
  return self.make_error(
851
860
  retcode=33001,
852
- message=f"账户 {account_name} (bot_id: {account.bot_id}) API调用超时: {endpoint}",
861
+ message=f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) API调用超时: {endpoint}",
853
862
  raw=None,
854
863
  )
855
864
 
@@ -901,14 +910,16 @@ class OneBotAdapter(BaseAdapter):
901
910
  )
902
911
  self.connections[account_name] = ws
903
912
  self.logger.info(
904
- f"账户 {account_name} (bot_id: {account.bot_id}) 连接成功"
913
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 连接成功"
905
914
  )
906
- await self.emit_meta("connect", account.bot_id)
915
+ await self.emit_meta("connect", self._get_bot_id(account_name))
916
+ if not self._get_bot_id(account_name):
917
+ self._pending_connect_meta.add(account_name)
907
918
  await self._listen(account_name)
908
919
  if not self._running:
909
920
  return
910
921
  self.logger.info(
911
- f"账户 {account_name} (bot_id: {account.bot_id}) "
922
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) "
912
923
  f"{self.default_retry_interval}秒后重连..."
913
924
  )
914
925
  await asyncio.sleep(self.default_retry_interval)
@@ -916,7 +927,7 @@ class OneBotAdapter(BaseAdapter):
916
927
  if not self._running:
917
928
  return
918
929
  self.logger.error(
919
- f"账户 {account_name} (bot_id: {account.bot_id}) 连接失败: {str(e)}"
930
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 连接失败: {str(e)}"
920
931
  )
921
932
  await asyncio.sleep(self.default_retry_interval)
922
933
 
@@ -950,12 +961,12 @@ class OneBotAdapter(BaseAdapter):
950
961
  self.logger.debug(f"账户 {account_name} 收到WS二进制数据")
951
962
  elif msg.type == WSMessage.CLOSE:
952
963
  self.logger.info(
953
- f"账户 {account_name} (bot_id: {account.bot_id}) 收到CLOSE帧"
964
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 收到CLOSE帧"
954
965
  )
955
966
  break
956
967
  elif msg.type == WSMessage.ERROR:
957
968
  self.logger.error(
958
- f"账户 {account_name} (bot_id: {account.bot_id}) 收到ERROR帧"
969
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 收到ERROR帧"
959
970
  )
960
971
  break
961
972
  else:
@@ -964,12 +975,12 @@ class OneBotAdapter(BaseAdapter):
964
975
  )
965
976
  except Exception as e:
966
977
  self.logger.error(
967
- f"账户 {account_name} (bot_id: {account.bot_id}) 监听异常: {str(e)}",
978
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 监听异常: {str(e)}",
968
979
  exc_info=True,
969
980
  )
970
981
  finally:
971
982
  try:
972
- await self.emit_meta("disconnect", account.bot_id if account else "")
983
+ await self.emit_meta("disconnect", self._get_bot_id(account_name) if account else "")
973
984
  except Exception:
974
985
  pass
975
986
  self.connections.pop(account_name, None)
@@ -1005,11 +1016,16 @@ class OneBotAdapter(BaseAdapter):
1005
1016
  onebot_event = self.convert(data)
1006
1017
  if onebot_event:
1007
1018
  raw_self_id = onebot_event.get("self", {}).get("user_id", "")
1008
- if raw_self_id and str(raw_self_id) not in self._self_id_map:
1009
- self._self_id_map[str(raw_self_id)] = account_name
1010
- self.logger.info(
1011
- f"映射 self_id {raw_self_id} 账户 {account_name}"
1012
- )
1019
+ if raw_self_id:
1020
+ self._update_bot_id(account_name, str(raw_self_id))
1021
+ if str(raw_self_id) not in self._self_id_map:
1022
+ self._self_id_map[str(raw_self_id)] = account_name
1023
+ self.logger.info(
1024
+ f"映射 self_id {raw_self_id} → 账户 {account_name}"
1025
+ )
1026
+ if account_name in self._pending_connect_meta:
1027
+ self._pending_connect_meta.discard(account_name)
1028
+ await self.emit_meta("connect", str(raw_self_id))
1013
1029
  await adapter_mgr.emit(onebot_event)
1014
1030
 
1015
1031
  except json.JSONDecodeError:
@@ -1031,12 +1047,14 @@ class OneBotAdapter(BaseAdapter):
1031
1047
  account = self.accounts.get(account_name)
1032
1048
  if account:
1033
1049
  self.logger.info(
1034
- f"账户 {account_name} (bot_id: {account.bot_id}) 客户端已连接"
1050
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 客户端已连接"
1035
1051
  )
1036
1052
 
1037
1053
  self.connections[account_name] = websocket
1038
1054
 
1039
- await self.emit_meta("connect", account.bot_id if account else "")
1055
+ await self.emit_meta("connect", self._get_bot_id(account_name) if account else "")
1056
+ if account and not self._get_bot_id(account_name):
1057
+ self._pending_connect_meta.add(account_name)
1040
1058
 
1041
1059
  try:
1042
1060
  while True:
@@ -1044,11 +1062,11 @@ class OneBotAdapter(BaseAdapter):
1044
1062
  asyncio.create_task(self._handle_message(data, account_name))
1045
1063
  except Exception:
1046
1064
  self.logger.info(
1047
- f"账户 {account_name} (bot_id: {account.bot_id if account else ''}) 客户端断开连接"
1065
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name) if account else ''}) 客户端断开连接"
1048
1066
  )
1049
1067
  finally:
1050
1068
  try:
1051
- await self.emit_meta("disconnect", account.bot_id if account else "")
1069
+ await self.emit_meta("disconnect", self._get_bot_id(account_name) if account else "")
1052
1070
  except Exception:
1053
1071
  pass
1054
1072
  if account_name in self.connections:
@@ -1081,7 +1099,7 @@ class OneBotAdapter(BaseAdapter):
1081
1099
 
1082
1100
  if client_token != account.token:
1083
1101
  self.logger.warning(
1084
- f"账户 {account_name} (bot_id: {account.bot_id}) Token无效"
1102
+ f"账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) Token无效"
1085
1103
  )
1086
1104
  await websocket.close(code=1008)
1087
1105
  return False
@@ -1116,7 +1134,7 @@ class OneBotAdapter(BaseAdapter):
1116
1134
  auth_handler=make_auth_handler(account_name),
1117
1135
  )
1118
1136
  self.logger.info(
1119
- f"已注册账户 {account_name} (bot_id: {account.bot_id}) 的Server路由: {path}"
1137
+ f"已注册账户 {account_name} (bot_id: {self._bot_id_display(account_name)}) 的Server路由: {path}"
1120
1138
  )
1121
1139
 
1122
1140
  async def start(self):
@@ -1140,7 +1158,7 @@ class OneBotAdapter(BaseAdapter):
1140
1158
  for account_name in client_accounts:
1141
1159
  account = self.accounts[account_name]
1142
1160
  self.logger.info(
1143
- f"启动Client模式账户: {account_name} (bot_id: {account.bot_id})"
1161
+ f"启动Client模式账户: {account_name} (bot_id: {self._bot_id_display(account_name)})"
1144
1162
  )
1145
1163
  self.reconnect_tasks[account_name] = asyncio.create_task(
1146
1164
  self.connect(account_name)
@@ -1169,7 +1187,7 @@ class OneBotAdapter(BaseAdapter):
1169
1187
  await connection.close()
1170
1188
  except Exception as e:
1171
1189
  self.logger.error(
1172
- f"关闭账户 {account_name} (bot_id: {account.bot_id if account else ''}) 连接失败: {str(e)}"
1190
+ f"关闭账户 {account_name} (bot_id: {self._bot_id_display(account_name) if account else ''}) 连接失败: {str(e)}"
1173
1191
  )
1174
1192
  self.connections.clear()
1175
1193
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot11Adapter
3
- Version: 4.1.0
3
+ Version: 4.1.1
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
- [OneBotv11_Adapter.accounts.main]
186
- mode = "server"
187
- server_path = "/onebot"
188
- server_token = "your_token_here"
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
- [OneBotv11_Adapter.accounts.backup]
302
+ # 备用账户(Client 模式,主动连接)
303
+ [OneBotAdapter.bots.backup]
304
+ bot_id = "987654321"
193
305
  mode = "client"
194
- client_url = "ws://127.0.0.1:3002"
195
- client_token = "backup_token_here"
306
+ url = "ws://127.0.0.1:3002" # 主动连接的WS地址
307
+ token = "backup_token_here"
196
308
  enabled = true
197
309
 
198
- # 测试账户配置
199
- [OneBotv11_Adapter.accounts.test]
310
+ # 测试账户(禁用状态)
311
+ [OneBotAdapter.bots.test]
312
+ bot_id = "111111111"
200
313
  mode = "client"
201
- client_url = "ws://127.0.0.1:3003"
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
- - `mode`: 运行模式,可选 "server"(服务端)或 "client"(客户端)
240
- - `server_path`: Server模式下的WebSocket路径
241
- - `server_token`: Server模式下的认证Token(可选)
242
- - `client_url`: Client模式下要连接的WebSocket地址
243
- - `client_token`: Client模式下的认证Token(可选)
244
- - `enabled`: 是否启用该账户(true/false)
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
- await onebot.Send.To("group", 123456).Account("main").Text("来自主账户的消息")
261
- await onebot.Send.To("group", 123456).Account("backup").Text("来自备用账户的消息")
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
- OneBot适配器支持两种方式监听事件:
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
- pass
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
- accounts = onebot.accounts
304
- print(f"已配置账户: {list(accounts.keys())}")
387
+ from ErisPulse.Core import adapter
388
+ onebot = adapter.get("onebot11")
305
389
 
306
- # 检查特定账户状态
307
- if "test" in accounts:
308
- main_account = accounts["test"]
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. 对于二进制内容(如图片、语音等),支持直接传入 bytes 数据。
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)
@@ -112,6 +112,97 @@ await onebot.Send.To("user", 123456).Edit(123456789, "修改后的内容")
112
112
  await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012", "345678"], "批量消息")
113
113
  ```
114
114
 
115
+ #### 群组管理:踢人
116
+ ```python
117
+ await onebot.Send.To("group", 123456).Kick(789012)
118
+ ```
119
+
120
+ #### 群组管理:禁言
121
+ ```python
122
+ await onebot.Send.To("group", 123456).Ban(789012, duration=1800) # 禁言30分钟
123
+ await onebot.Send.To("group", 123456).Ban(789012, duration=0) # 解除禁言
124
+ ```
125
+
126
+ #### 群组管理:全体禁言
127
+ ```python
128
+ await onebot.Send.To("group", 123456).WholeBan(enable=True)
129
+ ```
130
+
131
+ #### 群组管理:设置管理员
132
+ ```python
133
+ await onebot.Send.To("group", 123456).SetAdmin(789012, enable=True)
134
+ ```
135
+
136
+ #### 群组管理:设置群名片
137
+ ```python
138
+ await onebot.Send.To("group", 123456).SetCard(789012, "新名片")
139
+ ```
140
+
141
+ #### 群组管理:设置群名称
142
+ ```python
143
+ await onebot.Send.To("group", 123456).SetGroupName("新群名")
144
+ ```
145
+
146
+ #### 群组管理:退群
147
+ ```python
148
+ await onebot.Send.To("group", 123456).Leave()
149
+ ```
150
+
151
+ #### 群组管理:设置头衔
152
+ ```python
153
+ await onebot.Send.To("group", 123456).SetTitle(789012, "专属头衔")
154
+ ```
155
+
156
+ #### 群组管理:设置群头像
157
+ ```python
158
+ await onebot.Send.To("group", 123456).SetPortrait("http://example.com/avatar.jpg")
159
+ ```
160
+
161
+ #### 获取消息
162
+ ```python
163
+ await onebot.Send.GetMsg(123456789)
164
+ ```
165
+
166
+ #### 获取登录信息
167
+ ```python
168
+ await onebot.Send.GetLoginInfo()
169
+ ```
170
+
171
+ #### 获取好友列表
172
+ ```python
173
+ await onebot.Send.GetFriendList()
174
+ ```
175
+
176
+ #### 获取群信息
177
+ ```python
178
+ await onebot.Send.To("group", 123456).GetGroupInfo()
179
+ ```
180
+
181
+ #### 获取群列表
182
+ ```python
183
+ await onebot.Send.GetGroupList()
184
+ ```
185
+
186
+ #### 获取群成员信息
187
+ ```python
188
+ await onebot.Send.To("group", 123456).GetGroupMemberInfo(789012)
189
+ ```
190
+
191
+ #### 获取群成员列表
192
+ ```python
193
+ await onebot.Send.To("group", 123456).GetGroupMemberList()
194
+ ```
195
+
196
+ #### 发送文件
197
+ ```python
198
+ await onebot.Send.To("user", 123456).File("http://example.com/file.pdf")
199
+ ```
200
+
201
+ #### 点赞
202
+ ```python
203
+ await onebot.Send.To("user", 123456).Like(789012, times=10)
204
+ ```
205
+
115
206
  ---
116
207
 
117
208
  ## 支持的消息类型及对应方法
@@ -137,6 +228,25 @@ await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012"
137
228
  | `.Recall(message_id: Union[str, int])` | 撤回指定消息 | 消息管理 |
138
229
  | `.Edit(message_id: Union[str, int], new_text: str)` | 编辑消息(撤回+重发) | 消息管理 |
139
230
  | `.Batch(target_ids: List[str], text: str)` | 批量发送消息 | 群发功能 |
231
+ | `.File(file: Union[str, bytes], filename: str = "file.dat")` | 发送文件 | 文件传输 |
232
+ | `.Like(user_id: Union[str, int], times: int = 1)` | 发送好友赞 | 互动功能 |
233
+ | `.Kick(user_id: Union[str, int], reject_add_request: bool = False)` | 移除群成员 | 群组管理 |
234
+ | `.Ban(user_id: Union[str, int], duration: int = 1800)` | 群组禁言 | 群组管理 |
235
+ | `.WholeBan(enable: bool = True)` | 全体禁言 | 群组管理 |
236
+ | `.SetAdmin(user_id: Union[str, int], enable: bool = True)` | 设置管理员 | 群组管理 |
237
+ | `.SetCard(user_id: Union[str, int], card: str = "")` | 设置群名片 | 群组管理 |
238
+ | `.SetGroupName(name: str)` | 设置群名称 | 群组管理 |
239
+ | `.Leave(is_dismiss: bool = False)` | 退群/解散群 | 群组管理 |
240
+ | `.SetTitle(user_id: Union[str, int], title: str = "")` | 设置群头衔 | 群组管理 |
241
+ | `.SetPortrait(file: Union[str, bytes])` | 设置群头像 | 群组管理 |
242
+ | `.GetMsg(message_id: Union[str, int])` | 获取消息内容 | API |
243
+ | `.GetForwardMsg(id: Union[str, int])` | 获取合并转发消息 | API |
244
+ | `.GetLoginInfo()` | 获取登录号信息 | API |
245
+ | `.GetFriendList()` | 获取好友列表 | API |
246
+ | `.GetGroupInfo()` | 获取群信息(需To) | API |
247
+ | `.GetGroupList()` | 获取群列表 | API |
248
+ | `.GetGroupMemberInfo(user_id: Union[str, int])` | 获取群成员信息(需To) | API |
249
+ | `.GetGroupMemberList()` | 获取群成员列表(需To) | API |
140
250
 
141
251
  ---
142
252
 
@@ -144,76 +254,45 @@ await onebot.Send.To("user", [123456, 789012, 345678]).Batch(["123456", "789012"
144
254
 
145
255
  ### 多账户配置
146
256
 
147
- OneBot11适配器默认采用多账户配置结构:
257
+ OneBot11适配器支持多账户配置,每个 Bot 独立配置:
148
258
 
149
259
  ```toml
150
- # 主账户配置
151
- [OneBotv11_Adapter.accounts.main]
152
- mode = "server"
153
- server_path = "/onebot"
154
- server_token = "your_token_here"
260
+ # 主账户(Server 模式,被动接收连接)
261
+ [OneBotAdapter.bots.main]
262
+ bot_id = "123456789" # 机器人QQ号(必填)
263
+ mode = "server" # server 或 client
264
+ server_path = "/onebot" # WebSocket 路径
265
+ token = "your_token_here" # 认证Token
155
266
  enabled = true
156
267
 
157
- # 备用账户配置
158
- [OneBotv11_Adapter.accounts.backup]
268
+ # 备用账户(Client 模式,主动连接)
269
+ [OneBotAdapter.bots.backup]
270
+ bot_id = "987654321"
159
271
  mode = "client"
160
- client_url = "ws://127.0.0.1:3002"
161
- client_token = "backup_token_here"
272
+ url = "ws://127.0.0.1:3002" # 主动连接的WS地址
273
+ token = "backup_token_here"
162
274
  enabled = true
163
275
 
164
- # 测试账户配置
165
- [OneBotv11_Adapter.accounts.test]
276
+ # 测试账户(禁用状态)
277
+ [OneBotAdapter.bots.test]
278
+ bot_id = "111111111"
166
279
  mode = "client"
167
- client_url = "ws://127.0.0.1:3003"
168
- enabled = false # 禁用该账户
169
- ```
170
-
171
- ### 默认账户配置
172
-
173
- 如果没有配置文件,适配器会自动创建默认配置:
174
-
175
- ```toml
176
- [OneBotv11_Adapter.accounts.default]
177
- mode = "server"
178
- server_path = "/"
179
- server_token = ""
180
- client_url = "ws://127.0.0.1:3001"
181
- client_token = ""
182
- enabled = true
183
- ```
184
-
185
- ### 旧配置兼容性
186
-
187
- ```toml
188
- # 旧配置(仍支持,会显示迁移提醒)
189
- [OneBotv11_Adapter]
190
- mode = "server"
191
-
192
- [OneBotv11_Adapter.server]
193
- path = "/"
194
- token = ""
195
-
196
- [OneBotv11_Adapter.client]
197
- url = "ws://127.0.0.1:3001"
198
- token = ""
280
+ url = "ws://127.0.0.1:3003"
281
+ enabled = false
199
282
  ```
200
283
 
201
284
  ### 配置项说明
202
285
 
203
286
  每个账户独立配置以下选项:
204
287
 
205
- - `mode`: 运行模式,可选 "server"(服务端)或 "client"(客户端)
206
- - `server_path`: Server模式下的WebSocket路径
207
- - `server_token`: Server模式下的认证Token(可选)
208
- - `client_url`: Client模式下要连接的WebSocket地址
209
- - `client_token`: Client模式下的认证Token(可选)
210
- - `enabled`: 是否启用该账户(true/false)
211
-
212
- ### 内置默认值
213
-
214
- - 重连间隔:30秒
215
- - API调用超时:30秒
216
- - 最大重试次数:3次
288
+ | 配置项 | 类型 | 必填 | 说明 |
289
+ |--------|------|------|------|
290
+ | `bot_id` | string | 是 | 机器人QQ号 |
291
+ | `mode` | string | 否 | 运行模式:"server"(被动) 或 "client"(主动),默认 "server" |
292
+ | `token` | string | 否 | 认证Token(Server模式验证客户端 / Client模式发送认证头) |
293
+ | `server_path` | string | 否 | Server模式下WebSocket路径,默认 "/" |
294
+ | `url` | string | 否 | Client模式下要连接的WebSocket地址,默认 "ws://127.0.0.1:3001" |
295
+ | `enabled` | bool | 否 | 是否启用该账户,默认 true |
217
296
 
218
297
  ---
219
298
 
@@ -222,39 +301,45 @@ token = ""
222
301
  ### 多账户消息发送
223
302
 
224
303
  ```python
225
- # 使用指定账户发送消息
226
- await onebot.Send.To("group", 123456).Account("main").Text("来自主账户的消息")
227
- await onebot.Send.To("group", 123456).Account("backup").Text("来自备用账户的消息")
304
+ from ErisPulse.Core import adapter
305
+ onebot = adapter.get("onebot11")
306
+
307
+ # 使用账户名指定 Bot
308
+ await onebot.Send.Using("main").To("group", 123456).Text("来自主账户的消息")
309
+
310
+ # 使用 bot_id 指定 Bot
311
+ await onebot.Send.Using("987654321").To("group", 123456).Text("来自备用Bot的消息")
228
312
 
229
- # 使用默认账户发送(第一个启用的账户)
313
+ # 不指定时使用第一个启用的账户
230
314
  await onebot.Send.To("group", 123456).Text("来自默认账户的消息")
231
315
  ```
232
316
 
233
- 该方法会自动处理响应结果并返回,若超时将抛出异常。
234
-
235
317
  ---
236
318
 
237
319
  ## 事件处理
238
320
 
239
- OneBot适配器支持两种方式监听事件:
321
+ 推荐使用标准 Event 模块装饰器监听事件:
240
322
 
241
323
  ```python
242
- # 使用原始事件名
243
- @sdk.adapter.OneBot.on("message")
244
- async def handle_message(event):
245
- pass
324
+ from ErisPulse.Core.Event import message, notice, request
246
325
 
247
- # 使用映射后的事件名
248
- @sdk.adapter.OneBot.on("message")
326
+ @message.on_message()
249
327
  async def handle_message(event):
250
- pass
328
+ if event.get_platform() == "onebot11":
329
+ await event.reply(f"收到消息: {event.get_text()}")
330
+
331
+ @notice.on_notice()
332
+ async def handle_notice(event):
333
+ if event.get_platform() == "onebot11":
334
+ if event.get("detail_type") == "group_member_increase":
335
+ await event.reply(f"欢迎新成员!")
336
+
337
+ @request.on_friend_request()
338
+ async def handle_friend_request(event):
339
+ await event.reply("好友请求已收到")
251
340
  ```
252
341
 
253
- 支持的事件类型包括:
254
- - `message`: 消息事件
255
- - `notice`: 通知事件
256
- - `request`: 请求事件
257
- - `meta_event`: 元事件
342
+ 支持的事件类型:`message`、`notice`、`request`、`meta_event`。
258
343
 
259
344
  ---
260
345
 
@@ -262,17 +347,15 @@ async def handle_message(event):
262
347
 
263
348
  ### 多账户运行模式
264
349
 
265
- OneBot11适配器支持同时运行多个账户,每个账户可以独立配置为Server或Client模式:
350
+ OneBot11适配器支持同时运行多个账户,每个账户可以独立配置为 Server Client 模式:
266
351
 
267
352
  ```python
268
- # 查看所有账户
269
- accounts = onebot.accounts
270
- print(f"已配置账户: {list(accounts.keys())}")
353
+ from ErisPulse.Core import adapter
354
+ onebot = adapter.get("onebot11")
271
355
 
272
- # 检查特定账户状态
273
- if "test" in accounts:
274
- main_account = accounts["test"]
275
- print(f"主账户模式: {main_account.mode}, 启用状态: {main_account.enabled}")
356
+ # 查看所有账户
357
+ for name, account in onebot.accounts.items():
358
+ print(f"{name}: bot_id={account.bot_id}, mode={account.mode}, enabled={account.enabled}")
276
359
  ```
277
360
 
278
361
  ### Server 模式(作为服务端监听连接)
@@ -291,8 +374,10 @@ if "test" in accounts:
291
374
 
292
375
  ## 注意事项
293
376
 
294
- 1. 生产环境建议启用 Token 认证以保证安全性。
295
- 2. 对于二进制内容(如图片、语音等),支持直接传入 bytes 数据。
377
+ 1. 生产环境建议启用 Token 认证以保证安全性
378
+ 2. 二进制内容(图片、语音等)支持 `str`(URL/路径) 和 `bytes` 传入
379
+ 3. Server 模式下无需公网IP,Client 模式需 OneBot 服务端可被连接
380
+ 4. 每个 Server 模式账户会注册独立的 WebSocket 路由路径
296
381
 
297
382
  ---
298
383
 
@@ -300,5 +385,4 @@ if "test" in accounts:
300
385
 
301
386
  - [ErisPulse 主库](https://github.com/ErisPulse/ErisPulse/)
302
387
  - [OneBot V11 协议文档](https://github.com/botuniverse/onebot-11)
303
- - [go-cqhttp 项目地址](https://github.com/Mrs4s/go-cqhttp)
304
388
  - [模块开发指南](https://github.com/ErisPulse/ErisPulse/tree/main/docs/DEVELOPMENT.md)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse-OneBot11Adapter"
3
- version = "4.1.0"
3
+ version = "4.1.1"
4
4
  description = "ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"