ErisPulse-OneBot11Adapter 3.0.0__tar.gz → 3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot11Adapter
3
- Version: 3.0.0
3
+ Version: 3.0.2
4
4
  Summary: ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: MIT License
@@ -78,6 +78,10 @@ class OneBot11Converter:
78
78
  "user_id": str(raw_event.get("user_id", "")),
79
79
  "onebot11_message": raw_event["message"]
80
80
  })
81
+
82
+ # 添加非标准字段
83
+ if "user_nickname" in raw_event:
84
+ base_event["user_nickname"] = raw_event["user_nickname"]
81
85
 
82
86
  if detail_type == "group":
83
87
  base_event["group_id"] = str(raw_event.get("group_id", ""))
@@ -2,7 +2,7 @@ import asyncio
2
2
  import json
3
3
  import aiohttp
4
4
  from fastapi import WebSocket, WebSocketDisconnect
5
- from typing import Dict, List, Optional, Any, Type
5
+ from typing import Dict, List, Optional, Any, Type, Union
6
6
  from ErisPulse import sdk
7
7
  from ErisPulse.Core import adapter_server
8
8
 
@@ -18,15 +18,50 @@ class OneBotAdapter(sdk.BaseAdapter):
18
18
  message=text
19
19
  )
20
20
  )
21
+
22
+ def Image(self, file: Union[str, bytes], filename: str = "image.png"):
23
+ return self._send_media("image", file, filename)
21
24
 
22
- def Image(self, file: str):
23
- return self._send("image", {"file": file})
25
+ def Voice(self, file: Union[str, bytes], filename: str = "voice.amr"):
26
+ return self._send_media("voice", file, filename)
24
27
 
25
- def Voice(self, file: str):
26
- return self._send("voice", {"file": file})
28
+ def Video(self, file: Union[str, bytes], filename: str = "video.mp4"):
29
+ return self._send_media("video", file, filename)
27
30
 
28
- def Video(self, file: str):
29
- return self._send("video", {"file": file})
31
+ def _send_media(self, msg_type: str, file: Union[str, bytes], filename: str):
32
+ if isinstance(file, bytes):
33
+ return self._send_bytes(msg_type, file, filename)
34
+ else:
35
+ return self._send(msg_type, {"file": file})
36
+
37
+ def _send_bytes(self, msg_type: str, data: bytes, filename: str):
38
+ if msg_type in ["image", "voice"]:
39
+ try:
40
+ import base64
41
+ b64_data = base64.b64encode(data).decode('utf-8')
42
+ return self._send(msg_type, {"file": f"base64://{b64_data}"})
43
+ except Exception as e:
44
+ self._adapter.logger.warning(f"Base64发送失败,回退到临时文件方式: {str(e)}")
45
+
46
+ import tempfile
47
+ import os
48
+ import uuid
49
+
50
+ temp_dir = os.path.join(tempfile.gettempdir(), "onebot_media")
51
+ os.makedirs(temp_dir, exist_ok=True)
52
+ unique_filename = f"{uuid.uuid4().hex}_{filename}"
53
+ filepath = os.path.join(temp_dir, unique_filename)
54
+
55
+ with open(filepath, "wb") as f:
56
+ f.write(data)
57
+
58
+ try:
59
+ return self._send(msg_type, {"file": filepath})
60
+ finally:
61
+ try:
62
+ os.remove(filepath)
63
+ except:
64
+ pass
30
65
 
31
66
  def Raw(self, message_list):
32
67
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot11Adapter
3
- Version: 3.0.0
3
+ Version: 3.0.2
4
4
  Summary: ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse-OneBot11Adapter"
3
- version = "3.0.0"
3
+ version = "3.0.2"
4
4
  description = "ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"