新增小红书、XMPP、元宝、Zalo 四个渠道扩展。 小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor 元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
from yuxi.channel.extensions.xmpp.config import XmppConfig
|
|
from yuxi.channel.extensions.xmpp.types import ResolvedXmppAccount
|
|
|
|
|
|
def list_xmpp_account_ids(xmpp_cfg: dict) -> list[str]:
|
|
cfg = XmppConfig(**xmpp_cfg) if xmpp_cfg else XmppConfig()
|
|
if cfg.accounts:
|
|
return list(cfg.accounts.keys())
|
|
return ["default"]
|
|
|
|
|
|
def resolve_xmpp_account(xmpp_cfg: dict, account_id: str = "default") -> ResolvedXmppAccount:
|
|
cfg = XmppConfig(**xmpp_cfg) if xmpp_cfg else XmppConfig()
|
|
|
|
if account_id in cfg.accounts:
|
|
acct = cfg.accounts[account_id]
|
|
return ResolvedXmppAccount(
|
|
account_id=account_id,
|
|
enabled=acct.enabled,
|
|
name=acct.name or account_id,
|
|
jid=acct.jid,
|
|
password=acct.password,
|
|
host=acct.host,
|
|
port=acct.port,
|
|
use_ssl=acct.use_ssl,
|
|
resource=acct.resource,
|
|
nick=acct.nick,
|
|
rooms=acct.rooms,
|
|
dm_policy=acct.dm_policy,
|
|
group_policy=acct.group_policy,
|
|
allow_from=acct.allow_from,
|
|
group_allow_from=acct.group_allow_from,
|
|
room_configs=_dictify_room_configs(acct.room_configs),
|
|
room_passwords=acct.room_passwords,
|
|
dm_session_scope=acct.dm_session_scope,
|
|
)
|
|
|
|
return ResolvedXmppAccount(
|
|
account_id=account_id,
|
|
enabled=cfg.enabled,
|
|
jid=xmpp_cfg.get("jid", ""),
|
|
password=xmpp_cfg.get("password", ""),
|
|
host=xmpp_cfg.get("host", ""),
|
|
port=xmpp_cfg.get("port", 5222),
|
|
use_ssl=xmpp_cfg.get("use_ssl", False),
|
|
resource=xmpp_cfg.get("resource", "ForcePilot"),
|
|
nick=xmpp_cfg.get("nick", "Bot"),
|
|
rooms=xmpp_cfg.get("rooms", []),
|
|
dm_policy=xmpp_cfg.get("dm_policy", "open"),
|
|
group_policy=xmpp_cfg.get("group_policy", "open"),
|
|
allow_from=xmpp_cfg.get("allow_from", []),
|
|
group_allow_from=xmpp_cfg.get("group_allow_from", []),
|
|
room_configs=xmpp_cfg.get("room_configs", {}),
|
|
room_passwords=xmpp_cfg.get("room_passwords", {}),
|
|
dm_session_scope=xmpp_cfg.get("dm_session_scope", "per-user"),
|
|
)
|
|
|
|
|
|
def has_configured_state(xmpp_cfg: dict) -> bool:
|
|
cfg = XmppConfig(**xmpp_cfg) if xmpp_cfg else XmppConfig()
|
|
for acct in cfg.accounts.values():
|
|
if acct.jid and acct.password:
|
|
return True
|
|
return bool(xmpp_cfg.get("jid") and xmpp_cfg.get("password"))
|
|
|
|
|
|
def _dictify_room_configs(room_configs: dict) -> dict:
|
|
result = {}
|
|
for key, val in room_configs.items():
|
|
if hasattr(val, "model_dump"):
|
|
result[key] = val.model_dump()
|
|
else:
|
|
result[key] = val
|
|
return result
|