ErisPulse-OneBot12Adapter 4.3.0__tar.gz → 4.4.0__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-OneBot12Adapter
3
- Version: 4.3.0
3
+ Version: 4.4.0
4
4
  Summary: ErisPulse的OneBotV12协议适配模块,基线协议适配器
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: MIT License
@@ -15,12 +15,38 @@ try:
15
15
  except ImportError: # pragma: no cover
16
16
  spawn_background = None
17
17
 
18
- __version__ = "4.3.0"
18
+ __version__ = "4.4.0"
19
19
 
20
20
  # 软依赖的框架最低版本(运行时检测,仅提示不强制)
21
21
  MIN_FRAMEWORK_VERSION = (2, 7, 1)
22
22
 
23
23
 
24
+ def _forward_node_text(node: Dict) -> str:
25
+ """提取合并转发节点 content 中全部 text 段文本(段间直接连接)"""
26
+ data = node.get("data") or {}
27
+ return "".join(
28
+ str(seg.get("data", {}).get("text") or "")
29
+ for seg in (data.get("content") or [])
30
+ if isinstance(seg, dict) and seg.get("type") == "text"
31
+ )
32
+
33
+
34
+ def _forward_nodes_plain(nodes, separator: str = "\n") -> str:
35
+ """合并转发节点降级纯文本:每条「昵称: 正文」(OB12 标准无 node 段与转发 API)"""
36
+ lines = []
37
+ for node in nodes if isinstance(nodes, list) else [nodes]:
38
+ if not isinstance(node, dict):
39
+ continue
40
+ data = node.get("data") or {}
41
+ nickname = str(data.get("nickname") or "").strip()
42
+ text = _forward_node_text(node).strip()
43
+ if nickname and text:
44
+ lines.append(f"{nickname}: {text}")
45
+ elif text:
46
+ lines.append(text)
47
+ return separator.join(lines)
48
+
49
+
24
50
  @dataclass
25
51
  class OneBot12GlobalConfig(BaseConfig):
26
52
  """OneBot12 适配器全局配置"""
@@ -224,6 +250,14 @@ class OneBot12Adapter(BaseAdapter):
224
250
  if isinstance(message, dict):
225
251
  message = [message]
226
252
 
253
+ # node 段降级为纯文本原文输出(OB12 标准无 node 段,内容不丢失)
254
+ message = [
255
+ {"type": "text", "data": {"text": _forward_nodes_plain(seg)}}
256
+ if isinstance(seg, dict) and seg.get("type") == "node"
257
+ else seg
258
+ for seg in message
259
+ ]
260
+
227
261
  segments = self._apply_modifiers(message)
228
262
  self._reset_modifiers()
229
263
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-OneBot12Adapter
3
- Version: 4.3.0
3
+ Version: 4.4.0
4
4
  Summary: ErisPulse的OneBotV12协议适配模块,基线协议适配器
5
5
  Author-email: wsu2059q <wsu2059@qq.com>
6
6
  License: MIT License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse-OneBot12Adapter"
3
- version = "4.3.0"
3
+ version = "4.4.0"
4
4
  description = "ErisPulse的OneBotV12协议适配模块,基线协议适配器"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"