ErisPulse-OneBot11Adapter 4.1.1__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.
Files changed (15) hide show
  1. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/PKG-INFO +1 -1
  2. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/Core.py +73 -7
  3. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/PKG-INFO +1 -1
  4. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/pyproject.toml +1 -1
  5. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/SOURCES.txt +0 -0
  6. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/dependency_links.txt +0 -0
  7. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/entry_points.txt +0 -0
  8. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/requires.txt +0 -0
  9. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/ErisPulse_OneBot11Adapter.egg-info/top_level.txt +0 -0
  10. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/LICENSE +0 -0
  11. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/Converter.py +0 -0
  12. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/OneBotAdapter/__init__.py +0 -0
  13. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/README.md +0 -0
  14. {erispulse_onebot11adapter-4.1.1 → erispulse_onebot11adapter-4.1.2}/setup.cfg +0 -0
  15. {erispulse_onebot11adapter-4.1.1 → 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.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
@@ -169,10 +169,25 @@ class OneBotAdapter(BaseAdapter):
169
169
  """
170
170
  发送图片消息
171
171
 
172
- :param file: [Union[str, bytes]] 图片文件路径或 URL
172
+ 支持以下三种格式:
173
+ - bytes: 二进制数据,自动转换为 base64
174
+ - str (以 base64:// 开头): base64 编码字符串,直接透传
175
+ - str (其他): 视为文件路径,自动读取并转换为 base64
176
+
177
+ :param file: [Union[str, bytes]] 图片文件路径/URL/base64/二进制
173
178
  :param filename: [str] 文件名 (默认: "image.png")
174
179
  :return: [asyncio.Task] 发送任务
175
180
  """
181
+ import base64
182
+ import os
183
+
184
+ if isinstance(file, bytes):
185
+ file = "base64://" + base64.b64encode(file).decode("ascii")
186
+ elif isinstance(file, str) and not file.startswith("base64://"):
187
+ file_path = os.path.abspath(file)
188
+ with open(file_path, "rb") as f:
189
+ file = "base64://" + base64.b64encode(f.read()).decode("ascii")
190
+
176
191
  return self.Raw_ob12(
177
192
  [{"type": "image", "data": {"file": file, "file_name": filename}}]
178
193
  )
@@ -181,10 +196,25 @@ class OneBotAdapter(BaseAdapter):
181
196
  """
182
197
  发送语音消息
183
198
 
184
- :param file: [Union[str, bytes]] 语音文件路径或 URL
199
+ 支持以下三种格式:
200
+ - bytes: 二进制数据,自动转换为 base64
201
+ - str (以 base64:// 开头): base64 编码字符串,直接透传
202
+ - str (其他): 视为文件路径,自动读取并转换为 base64
203
+
204
+ :param file: [Union[str, bytes]] 语音文件路径/URL/base64/二进制
185
205
  :param filename: [str] 文件名 (默认: "voice.amr")
186
206
  :return: [asyncio.Task] 发送任务
187
207
  """
208
+ import base64
209
+ import os
210
+
211
+ if isinstance(file, bytes):
212
+ file = "base64://" + base64.b64encode(file).decode("ascii")
213
+ elif isinstance(file, str) and not file.startswith("base64://"):
214
+ file_path = os.path.abspath(file)
215
+ with open(file_path, "rb") as f:
216
+ file = "base64://" + base64.b64encode(f.read()).decode("ascii")
217
+
188
218
  return self.Raw_ob12(
189
219
  [{"type": "audio", "data": {"file": file, "file_name": filename}}]
190
220
  )
@@ -193,10 +223,25 @@ class OneBotAdapter(BaseAdapter):
193
223
  """
194
224
  发送视频消息
195
225
 
196
- :param file: [Union[str, bytes]] 视频文件路径或 URL
226
+ 支持以下三种格式:
227
+ - bytes: 二进制数据,自动转换为 base64
228
+ - str (以 base64:// 开头): base64 编码字符串,直接透传
229
+ - str (其他): 视为文件路径,自动读取并转换为 base64
230
+
231
+ :param file: [Union[str, bytes]] 视频文件路径/URL/base64/二进制
197
232
  :param filename: [str] 文件名 (默认: "video.mp4")
198
233
  :return: [asyncio.Task] 发送任务
199
234
  """
235
+ import base64
236
+ import os
237
+
238
+ if isinstance(file, bytes):
239
+ file = "base64://" + base64.b64encode(file).decode("ascii")
240
+ elif isinstance(file, str) and not file.startswith("base64://"):
241
+ file_path = os.path.abspath(file)
242
+ with open(file_path, "rb") as f:
243
+ file = "base64://" + base64.b64encode(f.read()).decode("ascii")
244
+
200
245
  return self.Raw_ob12(
201
246
  [{"type": "video", "data": {"file": file, "file_name": filename}}]
202
247
  )
@@ -214,10 +259,25 @@ class OneBotAdapter(BaseAdapter):
214
259
  """
215
260
  发送文件
216
261
 
217
- :param file: [Union[str, bytes]] 文件路径或 URL
262
+ 支持以下三种格式:
263
+ - bytes: 二进制数据,自动转换为 base64
264
+ - str (以 base64:// 开头): base64 编码字符串,直接透传
265
+ - str (其他): 视为文件路径,自动读取并转换为 base64
266
+
267
+ :param file: [Union[str, bytes]] 文件路径/URL/base64/二进制
218
268
  :param filename: [str] 文件名 (默认: "file.dat")
219
269
  :return: [asyncio.Task] 发送任务
220
270
  """
271
+ import base64
272
+ import os
273
+
274
+ if isinstance(file, bytes):
275
+ file = "base64://" + base64.b64encode(file).decode("ascii")
276
+ elif isinstance(file, str) and not file.startswith("base64://"):
277
+ file_path = os.path.abspath(file)
278
+ with open(file_path, "rb") as f:
279
+ file = "base64://" + base64.b64encode(f.read()).decode("ascii")
280
+
221
281
  return self.Raw_ob12(
222
282
  [{"type": "file", "data": {"file": file, "file_name": filename}}]
223
283
  )
@@ -980,7 +1040,9 @@ class OneBotAdapter(BaseAdapter):
980
1040
  )
981
1041
  finally:
982
1042
  try:
983
- await self.emit_meta("disconnect", self._get_bot_id(account_name) if account else "")
1043
+ await self.emit_meta(
1044
+ "disconnect", self._get_bot_id(account_name) if account else ""
1045
+ )
984
1046
  except Exception:
985
1047
  pass
986
1048
  self.connections.pop(account_name, None)
@@ -1052,7 +1114,9 @@ class OneBotAdapter(BaseAdapter):
1052
1114
 
1053
1115
  self.connections[account_name] = websocket
1054
1116
 
1055
- await self.emit_meta("connect", self._get_bot_id(account_name) if account else "")
1117
+ await self.emit_meta(
1118
+ "connect", self._get_bot_id(account_name) if account else ""
1119
+ )
1056
1120
  if account and not self._get_bot_id(account_name):
1057
1121
  self._pending_connect_meta.add(account_name)
1058
1122
 
@@ -1066,7 +1130,9 @@ class OneBotAdapter(BaseAdapter):
1066
1130
  )
1067
1131
  finally:
1068
1132
  try:
1069
- await self.emit_meta("disconnect", self._get_bot_id(account_name) if account else "")
1133
+ await self.emit_meta(
1134
+ "disconnect", self._get_bot_id(account_name) if account else ""
1135
+ )
1070
1136
  except Exception:
1071
1137
  pass
1072
1138
  if account_name in self.connections:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot11Adapter
3
- Version: 4.1.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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse-OneBot11Adapter"
3
- version = "4.1.1"
3
+ version = "4.1.2"
4
4
  description = "ErisPulse的OneBotV11协议适配模块,异步的OneBot触发器"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"