新增小红书、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
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
import re
|
|
|
|
|
|
def bare_jid_from(msg) -> str:
|
|
from_jid = msg["from"]
|
|
from slixmpp import JID
|
|
|
|
if isinstance(from_jid, JID):
|
|
return from_jid.bare
|
|
return str(from_jid).split("/")[0]
|
|
|
|
|
|
def extract_stanza_id(msg) -> str:
|
|
stanza_ids = msg["stanza_id"]
|
|
if stanza_ids:
|
|
for sid in stanza_ids.values():
|
|
return sid
|
|
return msg["id"]
|
|
|
|
|
|
def extract_thread_id(msg) -> str | None:
|
|
return msg["thread"] or None
|
|
|
|
|
|
def extract_muc_info(msg, msg_type: str) -> tuple[str | None, str | None]:
|
|
if msg_type != "groupchat":
|
|
return None, None
|
|
room_jid = msg["mucroom"]
|
|
muc_nick = msg["mucnick"]
|
|
return room_jid, muc_nick
|
|
|
|
|
|
def is_delayed_message(msg) -> bool:
|
|
delay = msg["delay"]
|
|
if delay and delay.get("stamp"):
|
|
return True
|
|
return False
|
|
|
|
|
|
def check_bot_mention(body: str, nick: str) -> bool:
|
|
if not body or not nick:
|
|
return False
|
|
pattern = re.compile(rf"\b{re.escape(nick)}\b[:,\s]?", re.IGNORECASE)
|
|
return bool(pattern.search(body))
|