新增小红书、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
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
logger = logging.getLogger("yuxi.channel.xmpp.status")
|
|
|
|
|
|
async def probe_xmpp(
|
|
jid: str,
|
|
host: str = "",
|
|
port: int = 5222,
|
|
use_ssl: bool = False,
|
|
timeout: float = 10.0,
|
|
) -> bool:
|
|
if not jid:
|
|
return False
|
|
|
|
from slixmpp import ClientXMPP
|
|
|
|
class ProbeBot(ClientXMPP):
|
|
def __init__(self, j, h, p, ssl):
|
|
super().__init__(j, "probe-only")
|
|
self.probe_ok = False
|
|
self._host = h
|
|
self._port = p
|
|
self._use_ssl = ssl
|
|
|
|
async def run_probe(self):
|
|
self.register_plugin("xep_0199")
|
|
try:
|
|
if self._host:
|
|
self.connect(address=(self._host, self._port), use_ssl=self._use_ssl)
|
|
else:
|
|
self.connect()
|
|
fut = asyncio.ensure_future(self.process(forever=False))
|
|
await asyncio.sleep(3.0)
|
|
self.disconnect()
|
|
try:
|
|
await asyncio.wait_for(fut, timeout=2.0)
|
|
except (TimeoutError, asyncio.CancelledError):
|
|
pass
|
|
self.probe_ok = True
|
|
except Exception:
|
|
self.probe_ok = False
|
|
|
|
bot = ProbeBot(jid, host, port, use_ssl)
|
|
try:
|
|
await asyncio.wait_for(bot.run_probe(), timeout=timeout)
|
|
except (TimeoutError, Exception):
|
|
return False
|
|
return bot.probe_ok
|
|
|
|
|
|
def build_xmpp_status_summary(snapshot) -> dict:
|
|
return {
|
|
"connected": getattr(snapshot, "connected", False),
|
|
"jid": getattr(snapshot, "jid", ""),
|
|
"rooms": getattr(snapshot, "rooms", []),
|
|
}
|