新增小红书、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
40 lines
1015 B
Python
40 lines
1015 B
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from enum import StrEnum
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class DmPolicyMode(StrEnum):
|
|
OPEN = "open"
|
|
PAIRING = "pairing"
|
|
ALLOWLIST = "allowlist"
|
|
DISABLED = "disabled"
|
|
|
|
|
|
class GroupPolicyMode(StrEnum):
|
|
OPEN = "open"
|
|
ALLOWLIST = "allowlist"
|
|
DISABLED = "disabled"
|
|
|
|
|
|
def check_dm_access(peer_id: str, policy: str, allowlist: list[str]) -> bool:
|
|
if policy == DmPolicyMode.OPEN:
|
|
return True
|
|
if policy == DmPolicyMode.DISABLED:
|
|
return False
|
|
if policy == DmPolicyMode.ALLOWLIST or policy == DmPolicyMode.PAIRING:
|
|
return peer_id in allowlist or "*" in allowlist
|
|
return True
|
|
|
|
|
|
def check_group_access(group_id: str, policy: str, allowlist: list[str]) -> bool:
|
|
if policy == GroupPolicyMode.OPEN:
|
|
return True
|
|
if policy == GroupPolicyMode.DISABLED:
|
|
return False
|
|
if policy == GroupPolicyMode.ALLOWLIST:
|
|
return group_id in allowlist or "*" in allowlist
|
|
return True
|