新增 Matrix 渠道扩展,支持在 Yuxi 平台中集成 Matrix 去中心化通讯协议。 包含以下功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - crypto: 端到端加密 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - room_resolver: 房间解析 - dm_tracker: 私聊追踪 - rate_limiter: 速率限制 - actions: 动作处理 - constants: 常量定义 - utils: 工具函数 - types: 类型定义
30 lines
965 B
Python
30 lines
965 B
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def get_olm_store_path(account_id: str = "default") -> str:
|
|
return f"data/matrix_store/{account_id}"
|
|
|
|
|
|
def is_decryption_failure(event) -> bool:
|
|
source = getattr(event, "source", {})
|
|
return source.get("type") == "m.room.encrypted" and "body" not in source.get("content", {})
|
|
|
|
|
|
def diagnose_decryption(event) -> dict:
|
|
source = getattr(event, "source", {})
|
|
content = source.get("content", {})
|
|
ciphertext = content.get("ciphertext", "")
|
|
return {
|
|
"event_id": getattr(event, "event_id", ""),
|
|
"room_id": getattr(event, "room_id", ""),
|
|
"has_body": "body" in content,
|
|
"algorithm": content.get("algorithm", "unknown"),
|
|
"sender_key": (content.get("sender_key", "") or "")[:16] + "...",
|
|
"session_id": content.get("session_id", "unknown"),
|
|
"ciphertext_len": len(ciphertext) if ciphertext else 0,
|
|
}
|