ForcePilot/backend/package/yuxi/channel/extensions/bluesky/security.py
Kris bb85da1ca2 feat(bluesky): 新增Bluesky (AT Protocol) 频道插件
实现了完整的Bluesky频道功能,支持私信轮询、@提及通知、账号会话管理、重复消息过滤、配对授权机制以及完整的API调用能力,包含配置schema和插件元数据定义
2026-05-21 10:40:50 +08:00

42 lines
1.6 KiB
Python

DM_POLICY_OPEN = "open"
DM_POLICY_PAIRING = "pairing"
DM_POLICY_ALLOWLIST = "allowlist"
DM_POLICY_DISABLED = "disabled"
VALID_DM_POLICIES = {
DM_POLICY_OPEN,
DM_POLICY_PAIRING,
DM_POLICY_ALLOWLIST,
DM_POLICY_DISABLED,
}
class BlueskySecurity:
def __init__(self):
self.default_policy = DM_POLICY_PAIRING
async def resolve_dm_policy(self, config: dict, account_id: str) -> str:
bluesky_cfg = config.get("channels", {}).get("bluesky", {})
account_cfg = bluesky_cfg.get("accounts", {}).get(account_id, bluesky_cfg)
policy = account_cfg.get("dmPolicy", self.default_policy)
return policy if policy in VALID_DM_POLICIES else self.default_policy
def resolve_allow_from(self, config: dict, account_id: str) -> list[str]:
bluesky_cfg = config.get("channels", {}).get("bluesky", {})
account_cfg = bluesky_cfg.get("accounts", {}).get(account_id, bluesky_cfg)
raw = account_cfg.get("allowFrom", [])
return [entry.replace("did:", "").strip().lower() for entry in raw if entry.strip()]
async def authorize(self, sender_did: str, dm_policy: str, allow_from: list[str]) -> str:
normalized = sender_did.strip().lower()
if dm_policy == DM_POLICY_OPEN:
return "allow"
if dm_policy == DM_POLICY_DISABLED:
return "block"
if dm_policy == DM_POLICY_ALLOWLIST:
return "allow" if normalized in allow_from else "block"
if dm_policy == DM_POLICY_PAIRING:
return "allow" if normalized in allow_from else "pairing"
return "block"