ErisPulse-WebhookAdapter 4.2.0__tar.gz → 4.3.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-WebhookAdapter
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: ErisPulse的Webhook通用桥接适配模块
5
5
  Author: ErisPulse
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse-WebhookAdapter
3
- Version: 4.2.0
3
+ Version: 4.3.0
4
4
  Summary: ErisPulse的Webhook通用桥接适配模块
5
5
  Author: ErisPulse
6
6
  License: MIT
@@ -11,7 +11,7 @@ from ErisPulse.Core.Bases.config_schema import dict_to_dataclass
11
11
  from ErisPulse.Core.Event import register_event_mixin, unregister_platform_event_methods
12
12
  from ErisPulse.Core.i18n import i18n
13
13
 
14
- __version__ = "4.2.0"
14
+ __version__ = "4.3.0"
15
15
 
16
16
  # 软依赖的框架最低版本(运行时检测,仅提示不强制)
17
17
  MIN_FRAMEWORK_VERSION = (2, 7, 1)
@@ -19,6 +19,32 @@ MIN_FRAMEWORK_VERSION = (2, 7, 1)
19
19
  from .Converter import WebhookConverter
20
20
 
21
21
 
22
+ def _forward_node_text(node: Dict) -> str:
23
+ """提取合并转发节点 content 中全部 text 段文本(段间直接连接)"""
24
+ data = node.get("data") or {}
25
+ return "".join(
26
+ str(seg.get("data", {}).get("text") or "")
27
+ for seg in (data.get("content") or [])
28
+ if isinstance(seg, dict) and seg.get("type") == "text"
29
+ )
30
+
31
+
32
+ def _forward_nodes_plain(nodes, separator: str = "\n") -> str:
33
+ """合并转发节点降级纯文本:每条「昵称: 正文」(Webhook 桥接无富文本能力)"""
34
+ lines = []
35
+ for node in nodes if isinstance(nodes, list) else [nodes]:
36
+ if not isinstance(node, dict):
37
+ continue
38
+ data = node.get("data") or {}
39
+ nickname = str(data.get("nickname") or "").strip()
40
+ text = _forward_node_text(node).strip()
41
+ if nickname and text:
42
+ lines.append(f"{nickname}: {text}")
43
+ elif text:
44
+ lines.append(text)
45
+ return separator.join(lines)
46
+
47
+
22
48
  @dataclass
23
49
  class WebhookAccountConfig(BotAccountConfig):
24
50
  """Webhook 桥接账户配置:一个账户 = 一个入站路径 + 一个出站 URL + 鉴权密钥"""
@@ -113,6 +139,17 @@ class WebhookAdapter(BaseAdapter):
113
139
  return self.Raw_ob12([{"type": "image", "data": {"file": file}}])
114
140
 
115
141
  def Raw_ob12(self, message: list, **kwargs):
142
+ if isinstance(message, dict):
143
+ message = [message]
144
+
145
+ # node 段降级为纯文本原文输出(内容不丢失)
146
+ message = [
147
+ {"type": "text", "data": {"text": _forward_nodes_plain(seg)}}
148
+ if isinstance(seg, dict) and seg.get("type") == "node"
149
+ else seg
150
+ for seg in message
151
+ ]
152
+
116
153
  async def _do_send():
117
154
  segments = self._apply_modifiers(message)
118
155
  ctx = self.send_context
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ErisPulse-WebhookAdapter"
3
- version = "4.2.0"
3
+ version = "4.3.0"
4
4
  description = "ErisPulse的Webhook通用桥接适配模块"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"