新增 Signal 渠道扩展,支持在 Yuxi 平台中集成 Signal 加密即时通讯渠道。 包含以下功能模块: - client: Signal 客户端封装 - daemon: signald 守护进程管理 - config_schema: 配置模式 - send: 消息发送 - accounts: 账户管理 - account_management: 账户综合管理 - access_policy: 访问策略 - identity: 身份管理 - profiles: 用户资料 - groups: 群组管理 - format: 消息格式转换 - normalize: 消息规范化 - dedupe: 消息去重 - monitor: 渠道状态监控 - probe: 健康探测 - sse_reconnect: SSE 重连机制
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
import logging
|
|
from typing import Any
|
|
|
|
from yuxi.channel.extensions.signal.client import SignalRpcClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def get_profile(client: SignalRpcClient, identifier: str, *, account: str | None = None) -> dict:
|
|
params: dict[str, Any] = {"recipient": identifier}
|
|
if account:
|
|
params["account"] = account
|
|
return await client.call("getProfile", params, account=account)
|
|
|
|
|
|
async def update_profile(
|
|
client: SignalRpcClient,
|
|
*,
|
|
name: str | None = None,
|
|
about: str | None = None,
|
|
avatar: str | None = None,
|
|
emoji: str | None = None,
|
|
account: str | None = None,
|
|
) -> None:
|
|
params: dict[str, Any] = {}
|
|
if name is not None:
|
|
params["name"] = name
|
|
if about is not None:
|
|
params["about"] = about
|
|
if avatar is not None:
|
|
params["avatar"] = avatar
|
|
if emoji is not None:
|
|
params["emoji"] = emoji
|
|
if account:
|
|
params["account"] = account
|
|
await client.call("updateProfile", params, account=account)
|
|
|
|
|
|
async def set_username(client: SignalRpcClient, username: str, *, account: str | None = None) -> None:
|
|
params: dict[str, Any] = {"username": username}
|
|
if account:
|
|
params["account"] = account
|
|
await client.call("setUsername", params, account=account)
|
|
|
|
|
|
async def list_contacts(client: SignalRpcClient, *, account: str | None = None) -> list[dict]:
|
|
result = await client.call("listContacts", account=account)
|
|
if isinstance(result, list):
|
|
return result
|
|
if isinstance(result, dict):
|
|
return result.get("contacts", [])
|
|
return []
|
|
|
|
|
|
async def list_accounts(client: SignalRpcClient) -> list[dict]:
|
|
result = await client.call("listAccounts")
|
|
if isinstance(result, list):
|
|
return result
|
|
if isinstance(result, dict):
|
|
return result.get("accounts", [])
|
|
return []
|
|
|
|
|
|
async def block_user(client: SignalRpcClient, identifier: str, *, account: str | None = None) -> None:
|
|
params: dict[str, Any] = {"recipient": identifier}
|
|
if account:
|
|
params["account"] = account
|
|
await client.call("block", params, account=account)
|
|
|
|
|
|
async def unblock_user(client: SignalRpcClient, identifier: str, *, account: str | None = None) -> None:
|
|
params: dict[str, Any] = {"recipient": identifier}
|
|
if account:
|
|
params["account"] = account
|
|
await client.call("unblock", params, account=account)
|
|
|
|
|
|
async def get_block_list(client: SignalRpcClient, *, account: str | None = None) -> list[str]:
|
|
result = await client.call("getBlockList", account=account)
|
|
if isinstance(result, list):
|
|
return result
|
|
if isinstance(result, dict):
|
|
return result.get("blocklist", [])
|
|
return []
|