ErisPulse 2.1.1__tar.gz → 2.1.3__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-2.1.1 → erispulse-2.1.3}/LICENSE +6 -4
- {erispulse-2.1.1 → erispulse-2.1.3}/PKG-INFO +7 -5
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AIDocs/ErisPulse-AdapterDev.md +317 -45
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AIDocs/ErisPulse-Core.md +71 -14
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AIDocs/ErisPulse-Full.md +360 -45
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AIDocs/ErisPulse-ModuleDev.md +106 -33
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/CHANGELOG.md +23 -1
- erispulse-2.1.3/docs/Development/Adapter.md +435 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/PlatformFeatures.md +43 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/adapter.md +16 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/env.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/logger.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/mods.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/raiserr.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/server.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/Core/util.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/__init__.md +33 -17
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/ErisPulse/__main__.md +2 -2
- {erispulse-2.1.1 → erispulse-2.1.3}/pyproject.toml +1 -1
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/__init__.py +14 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/adapter.py +28 -28
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/server.py +1 -1
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/__init__.py +42 -18
- erispulse-2.1.1/docs/Development/Adapter.md +0 -193
- {erispulse-2.1.1 → erispulse-2.1.3}/.github/assets/erispulse_logo.png +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.github/tools/merge_md.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.github/tools/update-api-docs.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.github/workflows/auto-tag-release.yml +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.github/workflows/pypi-publish.yml +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.gitignore +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/.python-version +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/CODE_OF_CONDUCT.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/devs/test.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/devs/test_adapter.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/devs/test_files/test.docx +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/devs/test_files/test.jpg +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/devs/test_files/test.mp4 +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AI-Module-Generation.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AdapterStandards/APIResponse.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AdapterStandards/EventConversion.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/AdapterStandards/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/CLI.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/Development/Module.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/Development/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/UseCore.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/api/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/docs/quick-start.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-adapter/LICENSE +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-adapter/MyAdapter/Core.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-adapter/MyAdapter/__init__.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-adapter/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-adapter/pyproject.toml +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-module/LICENSE +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-module/MyModule/Core.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-module/MyModule/__init__.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-module/README.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/examples/example-module/pyproject.toml +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/scripts/install/install.ps1 +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/scripts/install/install.sh +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/env.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/logger.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/mods.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/raiserr.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/shellprint.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/Core/util.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/src/ErisPulse/__main__.py +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/style_guide/DOCSTRING_SPEC.md +0 -0
- {erispulse-2.1.1 → erispulse-2.1.3}/style_guide/README.md +0 -0
|
@@ -22,8 +22,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
SOFTWARE.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
This SDK's core adapter standardization layer strictly follows OneBot12 specifications (https://12.onebot.dev/) for:
|
|
26
|
+
- Event data normalization
|
|
27
|
+
- API request/response formats
|
|
28
|
+
- Message segment definitions
|
|
29
|
+
- Metadata definitions
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
This ensures consistent behavior and interoperability across all adapter implementations.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ErisPulse
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.3
|
|
4
4
|
Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
|
|
5
5
|
Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>, runoneall <runoobsteve@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -27,11 +27,13 @@ License: MIT License
|
|
|
27
27
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
28
|
SOFTWARE.
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
This SDK's core adapter standardization layer strictly follows OneBot12 specifications (https://12.onebot.dev/) for:
|
|
31
|
+
- Event data normalization
|
|
32
|
+
- API request/response formats
|
|
33
|
+
- Message segment definitions
|
|
34
|
+
- Metadata definitions
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
This ensures consistent behavior and interoperability across all adapter implementations.
|
|
35
37
|
License-File: LICENSE
|
|
36
38
|
Classifier: Development Status :: 5 - Production/Stable
|
|
37
39
|
Classifier: Intended Audience :: Developers
|
|
@@ -170,7 +170,8 @@ MyAdapter/
|
|
|
170
170
|
├── LICENSE
|
|
171
171
|
└── MyAdapter/
|
|
172
172
|
├── __init__.py
|
|
173
|
-
|
|
173
|
+
├── Core.py
|
|
174
|
+
└── Converter.py
|
|
174
175
|
```
|
|
175
176
|
|
|
176
177
|
### 2. `pyproject.toml` 文件
|
|
@@ -212,15 +213,26 @@ from .Core import MyAdapter
|
|
|
212
213
|
```python
|
|
213
214
|
from ErisPulse import sdk
|
|
214
215
|
from ErisPulse.Core import BaseAdapter
|
|
216
|
+
from ErisPulse.Core import adapter_server
|
|
217
|
+
|
|
218
|
+
# 这里仅你使用 websocket 作为通信协议时需要 | 第一个作为参数的类型是 WebSocket, 第二个是 WebSocketDisconnect,当 ws 连接断开时触发你的捕捉
|
|
219
|
+
# 一般来说你不用在依赖中添加 fastapi, 因为它已经内置在 ErisPulse 中了
|
|
220
|
+
from fastapi import WebSocket, WebSocketDisconnect
|
|
215
221
|
|
|
216
222
|
class MyAdapter(BaseAdapter):
|
|
217
|
-
def __init__(self): #
|
|
223
|
+
def __init__(self, sdk): # 这里是不强制传入sdk的,你可以选择不传入
|
|
218
224
|
self.sdk = sdk
|
|
219
225
|
self.env = self.sdk.env
|
|
220
226
|
self.logger = self.sdk.logger
|
|
221
227
|
|
|
222
228
|
self.logger.info("MyModule 初始化完成")
|
|
223
229
|
self.config = self._get_config()
|
|
230
|
+
self.converter = self._setup_converter() # 获取转换器实例
|
|
231
|
+
self.convert = self.converter.convert
|
|
232
|
+
|
|
233
|
+
def _setup_converter(self):
|
|
234
|
+
from .Converter import MyPlatformConverter
|
|
235
|
+
return MyPlatformConverter()
|
|
224
236
|
|
|
225
237
|
def _get_config(self):
|
|
226
238
|
# 加载配置方法,你需要在这里进行必要的配置加载逻辑
|
|
@@ -232,29 +244,38 @@ class MyAdapter(BaseAdapter):
|
|
|
232
244
|
self.env.setConfig("MyAdapter", default_config)
|
|
233
245
|
return default_config
|
|
234
246
|
return config
|
|
247
|
+
|
|
235
248
|
class Send(BaseAdapter.Send): # 继承BaseAdapter内置的Send类
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
249
|
+
"""
|
|
250
|
+
Send消息发送DSL,支持四种调用方式(继承的Send类包含了To和Using方法):
|
|
251
|
+
1. 指定类型和ID: To(type,id).Func() -> 设置_target_type和_target_id/_target_to
|
|
252
|
+
示例: Send.To("group",123).Text("hi")
|
|
253
|
+
2. 指定发送账号: Using(account_id).Func() -> 设置_account_id
|
|
254
|
+
示例: Send.Using("bot1").Text("hi")
|
|
255
|
+
3. 组合使用: Using(account_id).To(type,id).Func()
|
|
256
|
+
示例: Send.Using("bot1").To("user","123").Text("hi")
|
|
257
|
+
4. 直接调用: Func() -> 不设置目标属性
|
|
258
|
+
示例: Send.Text("broadcast")
|
|
259
|
+
"""
|
|
239
260
|
|
|
240
|
-
# 可以重写Text方法提供平台特定实现
|
|
241
261
|
def Text(self, text: str):
|
|
262
|
+
"""发送文本消息(可重写实现)"""
|
|
242
263
|
return asyncio.create_task(
|
|
243
264
|
self._adapter.call_api(
|
|
244
265
|
endpoint="/send",
|
|
245
266
|
content=text,
|
|
246
|
-
recvId=self._target_id,
|
|
247
|
-
recvType=self._target_type
|
|
267
|
+
recvId=self._target_id, # 来自To()设置的属性
|
|
268
|
+
recvType=self._target_type # 来自To(type,id)设置的属性
|
|
248
269
|
)
|
|
249
270
|
)
|
|
250
271
|
|
|
251
|
-
# 添加新的消息类型
|
|
252
272
|
def Image(self, file: bytes):
|
|
273
|
+
"""发送图片消息"""
|
|
253
274
|
return asyncio.create_task(
|
|
254
275
|
self._adapter.call_api(
|
|
255
276
|
endpoint="/send_image",
|
|
256
277
|
file=file,
|
|
257
|
-
recvId=self._target_id,
|
|
278
|
+
recvId=self._target_id, # 自动使用To()设置的属性
|
|
258
279
|
recvType=self._target_type
|
|
259
280
|
)
|
|
260
281
|
)
|
|
@@ -318,12 +339,233 @@ class Send((BaseAdapter.Send):
|
|
|
318
339
|
)
|
|
319
340
|
```
|
|
320
341
|
|
|
321
|
-
|
|
342
|
+
调用方式支持以下组合:
|
|
343
|
+
|
|
344
|
+
1. 指定发送账号和接收目标:
|
|
345
|
+
```python
|
|
346
|
+
sdk.adapter.MyPlatform.Send.Using("bot1").To("user", "U1001").Text("你好")
|
|
347
|
+
```
|
|
322
348
|
|
|
349
|
+
2. 仅指定接收目标:
|
|
323
350
|
```python
|
|
324
351
|
sdk.adapter.MyPlatform.Send.To("user", "U1001").Text("你好")
|
|
325
352
|
```
|
|
326
353
|
|
|
354
|
+
3. 仅指定发送账号:
|
|
355
|
+
```python
|
|
356
|
+
sdk.adapter.MyPlatform.Send.Using("bot1").Text("广播消息")
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
4. 直接调用:
|
|
360
|
+
```python
|
|
361
|
+
sdk.adapter.MyPlatform.Send.Text("广播消息")
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
`Using`方法用于指定发送账号,会设置`self._account_id`属性,可以在后续API调用中使用。
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 5. 事件转换与路由注册
|
|
369
|
+
|
|
370
|
+
适配器需要处理平台原生事件并转换为OneBot12标准格式,同时需要向底层框架注册路由。以下是两种典型实现方式:
|
|
371
|
+
|
|
372
|
+
### 5.1 WebSocket 方式实现
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
async def _ws_handler(self, websocket: WebSocket):
|
|
376
|
+
"""WebSocket连接处理器"""
|
|
377
|
+
self.connection = websocket
|
|
378
|
+
self.logger.info("客户端已连接")
|
|
379
|
+
|
|
380
|
+
try:
|
|
381
|
+
while True:
|
|
382
|
+
data = await websocket.receive_text()
|
|
383
|
+
try:
|
|
384
|
+
event = json.loads(data)
|
|
385
|
+
# 提交原生事件到适配器
|
|
386
|
+
# 原生事件需要通过指定平台来获取 比如 sdk.adapter.MyPlatform.on("事件类型")
|
|
387
|
+
self.emit(data.get("event_type"), data)
|
|
388
|
+
|
|
389
|
+
# 转换为OneBot12标准事件
|
|
390
|
+
onebot_event = self.convert(event)
|
|
391
|
+
if onebot_event:
|
|
392
|
+
# 提交标准事件到框架 | 这里直接通过 sdk.adaoter.on("事件类型") 便可以获取到事件,但是需要判断字段里面的platform字段来区分适配器
|
|
393
|
+
await self.sdk.adapter.emit(onebot_event)
|
|
394
|
+
except json.JSONDecodeError:
|
|
395
|
+
self.logger.error(f"JSON解析失败: {data}")
|
|
396
|
+
except WebSocketDisconnect:
|
|
397
|
+
self.logger.info("客户端断开连接")
|
|
398
|
+
finally:
|
|
399
|
+
self.connection = None
|
|
400
|
+
|
|
401
|
+
async def start(self):
|
|
402
|
+
"""注册WebSocket路由"""
|
|
403
|
+
adapter_server.register_websocket(
|
|
404
|
+
adapter_name="myplatform", # 适配器名称
|
|
405
|
+
path="/ws", # 路由路径
|
|
406
|
+
handler=self._ws_handler, # 处理器
|
|
407
|
+
auth_handler=self._auth_handler # 认证处理器(可选)
|
|
408
|
+
)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### 5.2 WebHook 方式实现
|
|
412
|
+
|
|
413
|
+
```python
|
|
414
|
+
async def _webhook_handler(self, request: Request):
|
|
415
|
+
"""WebHook请求处理器"""
|
|
416
|
+
try:
|
|
417
|
+
data = await request.json()
|
|
418
|
+
|
|
419
|
+
# 提交原生事件到适配器
|
|
420
|
+
# 原生事件需要通过指定平台来获取 比如 sdk.adapter.MyPlatform.on("事件类型")
|
|
421
|
+
self.emit(data.get("event_type"), data)
|
|
422
|
+
|
|
423
|
+
# 转换为OneBot12标准事件
|
|
424
|
+
onebot_event = self.convert(data)=
|
|
425
|
+
if onebot_event:
|
|
426
|
+
# 提交标准事件到框架 | 这里直接通过 sdk.adaoter.on("事件类型") 便可以获取到事件,但是需要判断字段里面的platform字段来区分适配器
|
|
427
|
+
await self.sdk.adapter.emit(onebot_event)
|
|
428
|
+
return JSONResponse({"status": "ok"})
|
|
429
|
+
except Exception as e:
|
|
430
|
+
self.logger.error(f"处理WebHook失败: {str(e)}")
|
|
431
|
+
return JSONResponse({"status": "failed"}, status_code=400)
|
|
432
|
+
|
|
433
|
+
async def start(self):
|
|
434
|
+
"""注册WebHook路由"""
|
|
435
|
+
adapter_server.register_webhook(
|
|
436
|
+
adapter_name="myplatform", # 适配器名称
|
|
437
|
+
path="/webhook", # 路由路径
|
|
438
|
+
handler=self._webhook_handler, # 处理器
|
|
439
|
+
methods=["POST"] # 支持的HTTP方法
|
|
440
|
+
)
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### 5.3 事件转换器实现
|
|
444
|
+
|
|
445
|
+
适配器应提供标准的事件转换器,将平台原生事件转换为OneBot12格式(具体实现请参考[事件转换标准文档](docs/AdapterStandards/EventConversion.md):
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
class MyPlatformConverter:
|
|
449
|
+
def convert(self, raw_event: Dict) -> Optional[Dict]:
|
|
450
|
+
"""将平台原生事件转换为OneBot12标准格式"""
|
|
451
|
+
if not isinstance(raw_event, dict):
|
|
452
|
+
return None
|
|
453
|
+
|
|
454
|
+
# 基础事件结构
|
|
455
|
+
onebot_event = {
|
|
456
|
+
"id": str(raw_event.get("event_id", uuid.uuid4())),
|
|
457
|
+
"time": int(time.time()),
|
|
458
|
+
"type": "", # message/notice/request/meta_event
|
|
459
|
+
"detail_type": "",
|
|
460
|
+
"platform": "myplatform",
|
|
461
|
+
"self": {
|
|
462
|
+
"platform": "myplatform",
|
|
463
|
+
"user_id": str(raw_event.get("bot_id", ""))
|
|
464
|
+
},
|
|
465
|
+
"myplatform_raw": raw_event # 保留原始数据
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
# 根据事件类型分发处理
|
|
469
|
+
event_type = raw_event.get("type")
|
|
470
|
+
if event_type == "message":
|
|
471
|
+
return self._handle_message(raw_event, onebot_event)
|
|
472
|
+
elif event_type == "notice":
|
|
473
|
+
return self._handle_notice(raw_event, onebot_event)
|
|
474
|
+
|
|
475
|
+
return None
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
## 6. API响应标准
|
|
479
|
+
|
|
480
|
+
适配器的`call_api`方法必须返回符合以下标准的响应结构:
|
|
481
|
+
|
|
482
|
+
### 6.1 成功响应格式
|
|
483
|
+
|
|
484
|
+
```python
|
|
485
|
+
{
|
|
486
|
+
"status": "ok", # 必须
|
|
487
|
+
"retcode": 0, # 必须,0表示成功
|
|
488
|
+
"data": { # 必须,成功时返回的数据
|
|
489
|
+
"message_id": "123456", # 消息ID(如果有)
|
|
490
|
+
"time": 1632847927.599013 # 时间戳(如果有)
|
|
491
|
+
},
|
|
492
|
+
"message": "", # 必须,成功时为空字符串
|
|
493
|
+
"message_id": "123456", # 可选,消息ID
|
|
494
|
+
"echo": "1234", # 可选,当请求中包含echo时返回
|
|
495
|
+
"myplatform_raw": {...} # 可选,原始响应数据
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### 6.2 失败响应格式
|
|
500
|
+
|
|
501
|
+
```python
|
|
502
|
+
{
|
|
503
|
+
"status": "failed", # 必须
|
|
504
|
+
"retcode": 10003, # 必须,非0错误码
|
|
505
|
+
"data": None, # 必须,失败时为null
|
|
506
|
+
"message": "缺少必要参数", # 必须,错误描述
|
|
507
|
+
"message_id": "", # 可选,失败时为空字符串
|
|
508
|
+
"echo": "1234", # 可选,当请求中包含echo时返回
|
|
509
|
+
"myplatform_raw": {...} # 可选,原始响应数据
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### 6.3 实现示例
|
|
514
|
+
|
|
515
|
+
```python
|
|
516
|
+
async def call_api(self, endpoint: str, **params):
|
|
517
|
+
try:
|
|
518
|
+
# 调用平台API
|
|
519
|
+
raw_response = await self._platform_api_call(endpoint, **params)
|
|
520
|
+
|
|
521
|
+
# 标准化响应
|
|
522
|
+
standardized = {
|
|
523
|
+
"status": "ok" if raw_response["success"] else "failed",
|
|
524
|
+
"retcode": 0 if raw_response["success"] else raw_response.get("code", 10001),
|
|
525
|
+
"data": raw_response.get("data"),
|
|
526
|
+
"message": raw_response.get("message", ""),
|
|
527
|
+
"message_id": raw_response.get("data", {}).get("message_id", ""),
|
|
528
|
+
"myplatform_raw": raw_response
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if "echo" in params:
|
|
532
|
+
standardized["echo"] = params["echo"]
|
|
533
|
+
|
|
534
|
+
return standardized
|
|
535
|
+
|
|
536
|
+
except Exception as e:
|
|
537
|
+
return {
|
|
538
|
+
"status": "failed",
|
|
539
|
+
"retcode": 34000, # 平台错误代码段
|
|
540
|
+
"data": None,
|
|
541
|
+
"message": str(e),
|
|
542
|
+
"message_id": ""
|
|
543
|
+
}
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
## 7. 错误代码规范
|
|
547
|
+
|
|
548
|
+
适配器应遵循以下错误代码范围:
|
|
549
|
+
|
|
550
|
+
| 代码范围 | 类型 | 说明 |
|
|
551
|
+
|---------|------|------|
|
|
552
|
+
| 0 | 成功 | 必须为0 |
|
|
553
|
+
| 1xxxx | 请求错误 | 无效参数、不支持的操作等 |
|
|
554
|
+
| 2xxxx | 处理器错误 | 适配器内部处理错误 |
|
|
555
|
+
| 3xxxx | 执行错误 | 平台API调用错误 |
|
|
556
|
+
| 34xxx | 平台错误 | 平台返回的错误 |
|
|
557
|
+
|
|
558
|
+
建议在适配器中定义常量:
|
|
559
|
+
|
|
560
|
+
```python
|
|
561
|
+
class ErrorCode:
|
|
562
|
+
SUCCESS = 0
|
|
563
|
+
INVALID_PARAMS = 10003
|
|
564
|
+
UNSUPPORTED_ACTION = 10002
|
|
565
|
+
INTERNAL_ERROR = 20001
|
|
566
|
+
PLATFORM_ERROR = 34000
|
|
567
|
+
```
|
|
568
|
+
|
|
327
569
|
---
|
|
328
570
|
|
|
329
571
|
## 开发建议
|
|
@@ -350,7 +592,7 @@ sdk.adapter.MyPlatform.Send.To("user", "U1001").Text("你好")
|
|
|
350
592
|
|
|
351
593
|
---
|
|
352
594
|
|
|
353
|
-
*文档最后更新于 2025-07-17
|
|
595
|
+
*文档最后更新于 2025-07-17 12:44:51*
|
|
354
596
|
|
|
355
597
|
<!--- End of Adapter.md -->
|
|
356
598
|
|
|
@@ -690,7 +932,7 @@ def generate_message_id(platform: str, raw_id: str) -> str:
|
|
|
690
932
|
|
|
691
933
|
# 📦 `ErisPulse.__init__` 模块
|
|
692
934
|
|
|
693
|
-
*自动生成于 2025-07-16
|
|
935
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
694
936
|
|
|
695
937
|
---
|
|
696
938
|
|
|
@@ -835,6 +1077,31 @@ SDK初始化入口
|
|
|
835
1077
|
|
|
836
1078
|
---
|
|
837
1079
|
|
|
1080
|
+
##### `__str__`
|
|
1081
|
+
|
|
1082
|
+
转换为字符串时触发初始化
|
|
1083
|
+
|
|
1084
|
+
:return: str 模块字符串表示
|
|
1085
|
+
|
|
1086
|
+
---
|
|
1087
|
+
|
|
1088
|
+
##### `__copy__`
|
|
1089
|
+
|
|
1090
|
+
浅拷贝时返回自身,保持懒加载特性
|
|
1091
|
+
|
|
1092
|
+
:return: self
|
|
1093
|
+
|
|
1094
|
+
---
|
|
1095
|
+
|
|
1096
|
+
##### `__deepcopy__`
|
|
1097
|
+
|
|
1098
|
+
深拷贝时返回自身,保持懒加载特性
|
|
1099
|
+
|
|
1100
|
+
:param memo: memo
|
|
1101
|
+
:return: self
|
|
1102
|
+
|
|
1103
|
+
---
|
|
1104
|
+
|
|
838
1105
|
### `AdapterLoader`
|
|
839
1106
|
|
|
840
1107
|
适配器加载器
|
|
@@ -969,13 +1236,17 @@ SDK初始化入口
|
|
|
969
1236
|
|
|
970
1237
|
---
|
|
971
1238
|
|
|
972
|
-
##### `
|
|
1239
|
+
##### `_initialize_modules`
|
|
1240
|
+
|
|
1241
|
+
⚠️ **内部方法**:
|
|
973
1242
|
|
|
974
|
-
|
|
1243
|
+
初始化模块
|
|
975
1244
|
|
|
976
1245
|
:param modules: List[str] 模块名称列表
|
|
977
1246
|
:param module_objs: Dict[str, Any] 模块对象字典
|
|
978
1247
|
|
|
1248
|
+
:return: bool 模块初始化是否成功
|
|
1249
|
+
|
|
979
1250
|
---
|
|
980
1251
|
|
|
981
1252
|
##### `_register_adapters`
|
|
@@ -991,27 +1262,14 @@ SDK初始化入口
|
|
|
991
1262
|
|
|
992
1263
|
---
|
|
993
1264
|
|
|
994
|
-
##### `_initialize_modules`
|
|
995
|
-
|
|
996
|
-
⚠️ **内部方法**:
|
|
997
1265
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
:param modules: List[str] 模块名称列表
|
|
1001
|
-
:param module_objs: Dict[str, Any] 模块对象字典
|
|
1002
|
-
|
|
1003
|
-
:return: bool 模块初始化是否成功
|
|
1004
|
-
|
|
1005
|
-
---
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
*文档最后更新于 2025-07-16 15:34:26*
|
|
1266
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
1009
1267
|
|
|
1010
1268
|
## ErisPulse\__main__.md
|
|
1011
1269
|
|
|
1012
1270
|
# 📦 `ErisPulse.__main__` 模块
|
|
1013
1271
|
|
|
1014
|
-
*自动生成于 2025-07-16
|
|
1272
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
1015
1273
|
|
|
1016
1274
|
---
|
|
1017
1275
|
|
|
@@ -1200,13 +1458,13 @@ PyPI包管理器
|
|
|
1200
1458
|
---
|
|
1201
1459
|
|
|
1202
1460
|
|
|
1203
|
-
*文档最后更新于 2025-07-16
|
|
1461
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
1204
1462
|
|
|
1205
1463
|
## ErisPulse\Core\adapter.md
|
|
1206
1464
|
|
|
1207
1465
|
# 📦 `ErisPulse.Core.adapter` 模块
|
|
1208
1466
|
|
|
1209
|
-
*自动生成于 2025-07-16
|
|
1467
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
1210
1468
|
|
|
1211
1469
|
---
|
|
1212
1470
|
|
|
@@ -1248,6 +1506,7 @@ ErisPulse 适配器系统
|
|
|
1248
1506
|
:param adapter: 所属适配器实例
|
|
1249
1507
|
:param target_type: 目标类型(可选)
|
|
1250
1508
|
:param target_id: 目标ID(可选)
|
|
1509
|
+
:param _account_id: 发送账号(可选)
|
|
1251
1510
|
|
|
1252
1511
|
---
|
|
1253
1512
|
|
|
@@ -1265,6 +1524,19 @@ ErisPulse 适配器系统
|
|
|
1265
1524
|
|
|
1266
1525
|
---
|
|
1267
1526
|
|
|
1527
|
+
##### `Using`
|
|
1528
|
+
|
|
1529
|
+
设置发送账号
|
|
1530
|
+
|
|
1531
|
+
:param _account_id: 发送账号
|
|
1532
|
+
:return: SendDSL实例
|
|
1533
|
+
|
|
1534
|
+
:example:
|
|
1535
|
+
>>> adapter.Send.Using("bot1").To("123").Text("Hello")
|
|
1536
|
+
>>> adapter.Send.To("123").Using("bot1").Text("Hello") # 支持乱序
|
|
1537
|
+
|
|
1538
|
+
---
|
|
1539
|
+
|
|
1268
1540
|
### `BaseAdapter`
|
|
1269
1541
|
|
|
1270
1542
|
适配器基类
|
|
@@ -1537,13 +1809,13 @@ OneBot12协议事件监听装饰器
|
|
|
1537
1809
|
---
|
|
1538
1810
|
|
|
1539
1811
|
|
|
1540
|
-
*文档最后更新于 2025-07-16
|
|
1812
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
1541
1813
|
|
|
1542
1814
|
## ErisPulse\Core\env.md
|
|
1543
1815
|
|
|
1544
1816
|
# 📦 `ErisPulse.Core.env` 模块
|
|
1545
1817
|
|
|
1546
|
-
*自动生成于 2025-07-16
|
|
1818
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
1547
1819
|
|
|
1548
1820
|
---
|
|
1549
1821
|
|
|
@@ -1829,13 +2101,13 @@ ErisPulse 环境配置模块
|
|
|
1829
2101
|
---
|
|
1830
2102
|
|
|
1831
2103
|
|
|
1832
|
-
*文档最后更新于 2025-07-16
|
|
2104
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
1833
2105
|
|
|
1834
2106
|
## ErisPulse\Core\logger.md
|
|
1835
2107
|
|
|
1836
2108
|
# 📦 `ErisPulse.Core.logger` 模块
|
|
1837
2109
|
|
|
1838
|
-
*自动生成于 2025-07-16
|
|
2110
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
1839
2111
|
|
|
1840
2112
|
---
|
|
1841
2113
|
|
|
@@ -1917,13 +2189,13 @@ ErisPulse 日志系统
|
|
|
1917
2189
|
---
|
|
1918
2190
|
|
|
1919
2191
|
|
|
1920
|
-
*文档最后更新于 2025-07-16
|
|
2192
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
1921
2193
|
|
|
1922
2194
|
## ErisPulse\Core\mods.md
|
|
1923
2195
|
|
|
1924
2196
|
# 📦 `ErisPulse.Core.mods` 模块
|
|
1925
2197
|
|
|
1926
|
-
*自动生成于 2025-07-16
|
|
2198
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
1927
2199
|
|
|
1928
2200
|
---
|
|
1929
2201
|
|
|
@@ -2106,13 +2378,13 @@ ErisPulse 模块管理器
|
|
|
2106
2378
|
---
|
|
2107
2379
|
|
|
2108
2380
|
|
|
2109
|
-
*文档最后更新于 2025-07-16
|
|
2381
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
2110
2382
|
|
|
2111
2383
|
## ErisPulse\Core\raiserr.md
|
|
2112
2384
|
|
|
2113
2385
|
# 📦 `ErisPulse.Core.raiserr` 模块
|
|
2114
2386
|
|
|
2115
|
-
*自动生成于 2025-07-16
|
|
2387
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
2116
2388
|
|
|
2117
2389
|
---
|
|
2118
2390
|
|
|
@@ -2216,13 +2488,13 @@ ErisPulse 错误管理系统
|
|
|
2216
2488
|
---
|
|
2217
2489
|
|
|
2218
2490
|
|
|
2219
|
-
*文档最后更新于 2025-07-16
|
|
2491
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
2220
2492
|
|
|
2221
2493
|
## ErisPulse\Core\server.md
|
|
2222
2494
|
|
|
2223
2495
|
# 📦 `ErisPulse.Core.server` 模块
|
|
2224
2496
|
|
|
2225
|
-
*自动生成于 2025-07-16
|
|
2497
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
2226
2498
|
|
|
2227
2499
|
---
|
|
2228
2500
|
|
|
@@ -2343,13 +2615,13 @@ ErisPulse Adapter Server
|
|
|
2343
2615
|
---
|
|
2344
2616
|
|
|
2345
2617
|
|
|
2346
|
-
*文档最后更新于 2025-07-16
|
|
2618
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
2347
2619
|
|
|
2348
2620
|
## ErisPulse\Core\util.md
|
|
2349
2621
|
|
|
2350
2622
|
# 📦 `ErisPulse.Core.util` 模块
|
|
2351
2623
|
|
|
2352
|
-
*自动生成于 2025-07-16
|
|
2624
|
+
*自动生成于 2025-07-17 16:57:03*
|
|
2353
2625
|
|
|
2354
2626
|
---
|
|
2355
2627
|
|
|
@@ -2443,6 +2715,6 @@ ErisPulse 工具函数集合
|
|
|
2443
2715
|
---
|
|
2444
2716
|
|
|
2445
2717
|
|
|
2446
|
-
*文档最后更新于 2025-07-16
|
|
2718
|
+
*文档最后更新于 2025-07-17 16:57:03*
|
|
2447
2719
|
|
|
2448
2720
|
<!--- End of API文档 -->
|