新增小红书、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
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import logging
|
|
|
|
from yuxi.channel.extensions.xiaohongshu.types import XiaohongshuAccount
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class XiaohongshuSecurity:
|
|
|
|
VALID_POLICIES = {"open", "pairing", "allowlist", "disabled"}
|
|
|
|
def __init__(self, account: XiaohongshuAccount | None = None):
|
|
self._account = account
|
|
if account and account.dm_policy in self.VALID_POLICIES:
|
|
self._policy = account.dm_policy
|
|
else:
|
|
self._policy = "open"
|
|
self._allowlist: set[str] = set(account.allow_from) if account else set()
|
|
|
|
def resolve_dm_policy(self) -> str:
|
|
return self._policy
|
|
|
|
def check_allowlist(self, open_id: str, channel_type: str = "xiaohongshu") -> bool:
|
|
if self._policy == "open":
|
|
return True
|
|
if self._policy == "disabled":
|
|
return False
|
|
if not self._allowlist:
|
|
logger.warning("allowlist is empty with policy=%s", self._policy)
|
|
return False
|
|
return open_id in self._allowlist
|
|
|
|
def add_to_allowlist(self, open_id: str):
|
|
self._allowlist.add(open_id)
|
|
|
|
def remove_from_allowlist(self, open_id: str):
|
|
self._allowlist.discard(open_id)
|