ForcePilot/backend/package/yuxi/channel/extensions/douyin/security.py
Kris 4552bde837 feat(douyin): 新增抖音渠道插件,支持私信收发与相关能力
该提交实现了完整的抖音开放平台IM渠道插件,包含:
1. 基础配置与账号管理能力
2. 消息去重、安全策略校验
3. 流式回复、多媒体消息发送
4. Webhook回调处理与事件解析
5. 配对认证与流量限流机制
2026-05-21 10:45:37 +08:00

37 lines
1.1 KiB
Python

import logging
from yuxi.channel.extensions.douyin.types import DouyinAccount
logger = logging.getLogger(__name__)
class DouyinSecurity:
VALID_POLICIES = {"open", "pairing", "allowlist", "disabled"}
def __init__(self, account: DouyinAccount | 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 = "douyin") -> 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)