新增了完整的Signal渠道适配器实现,包含RPC客户端、守护进程管理、安全策略、消息处理、安装配置工具等全套功能,支持通过signal-cli与Signal网络进行通信,包含账户管理、消息收发、反应处理、媒体分析、健康检查等能力。
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.adapters.signal.client import RpcClient, RpcError
|
|
from yuxi.channels.adapters.signal.identity import get_identities
|
|
|
|
|
|
async def list_peers(
|
|
rpc_client: RpcClient,
|
|
account: str,
|
|
query: str | None = None,
|
|
trust_level: str | None = None,
|
|
) -> list[dict]:
|
|
try:
|
|
identities = await get_identities(rpc_client, account)
|
|
result = []
|
|
for i in identities:
|
|
entry = {
|
|
"number": i.get("number", ""),
|
|
"name": i.get("name", ""),
|
|
"trust_level": i.get("trustLevel", "UNTRUSTED"),
|
|
"fingerprint": i.get("fingerprint", ""),
|
|
}
|
|
if query and not _match_query(entry, query):
|
|
continue
|
|
if trust_level and entry["trust_level"].upper() != trust_level.upper():
|
|
continue
|
|
result.append(entry)
|
|
return result
|
|
except RpcError:
|
|
return []
|
|
|
|
|
|
async def list_groups(
|
|
rpc_client: RpcClient,
|
|
account: str,
|
|
name_filter: str | None = None,
|
|
) -> list[dict]:
|
|
try:
|
|
result = await rpc_client.call("listGroups", {"account": account})
|
|
groups = result.get("groups", [])
|
|
entries = []
|
|
for g in groups:
|
|
entry = {
|
|
"group_id": g.get("groupId", g.get("id", "")),
|
|
"name": g.get("name", ""),
|
|
"description": g.get("description", ""),
|
|
"member_count": g.get("memberCount", 0),
|
|
}
|
|
if name_filter and name_filter.lower() not in entry["name"].lower():
|
|
continue
|
|
entries.append(entry)
|
|
return entries
|
|
except RpcError:
|
|
return []
|
|
|
|
|
|
def _match_query(entry: dict, query: str) -> bool:
|
|
q = query.lower()
|
|
return (
|
|
q in entry.get("number", "").lower()
|
|
or q in entry.get("name", "").lower()
|
|
or q in entry.get("fingerprint", "").lower()
|
|
)
|