该提交新增了完整的BlueBubbles渠道插件,支持通过BlueBubbles Server集成iMessage功能,包含以下核心能力: 1. 支持私聊和群聊会话管理,自动区分会话类型 2. 完整的消息收发支持,包括文本、图片、语音、文件、视频消息 3. 支持消息反应、已读回执、消息编辑与撤回 4. 内置去重、防抖处理机制 5. 支持Webhook和WebSocket两种事件接收方式 6. 完善的权限与安全校验机制 7. 历史消息同步与抓包功能 8. TTS语音合成与发送支持 9. 群组管理能力,包括重命名、修改头像、增减成员等
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
import logging
|
|
|
|
from yuxi.channel.extensions.bluebubbles.config import BlueBubblesConfigAdapter
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
config_adapter = BlueBubblesConfigAdapter()
|
|
|
|
|
|
class BlueBubblesSecurity:
|
|
def __init__(self):
|
|
self._config_adapter = config_adapter
|
|
|
|
async def check_dm_access(self, config: dict, peer_id: str) -> bool:
|
|
channel_config = self._config_adapter._get_channel_config(config)
|
|
dm_policy = channel_config.get("dmPolicy", "pairing")
|
|
|
|
if dm_policy == "disabled":
|
|
return False
|
|
|
|
if dm_policy == "open":
|
|
return True
|
|
|
|
allow_from = channel_config.get("allowFrom", [])
|
|
if peer_id in allow_from:
|
|
return True
|
|
|
|
if dm_policy == "pairing":
|
|
return False
|
|
|
|
return False
|
|
|
|
async def check_group_access(self, config: dict, chat_guid: str, sender_handle: str) -> bool:
|
|
channel_config = self._config_adapter._get_channel_config(config)
|
|
group_policy = channel_config.get("groupPolicy", "allowlist")
|
|
|
|
if group_policy == "disabled":
|
|
return False
|
|
|
|
if group_policy == "open":
|
|
return True
|
|
|
|
group_allow_from = channel_config.get("groupAllowFrom", [])
|
|
if sender_handle in group_allow_from:
|
|
return True
|
|
|
|
groups = channel_config.get("groups", {})
|
|
if "*" in groups:
|
|
return True
|
|
|
|
if chat_guid in groups:
|
|
return True
|
|
|
|
return False
|
|
|
|
def resolve_dm_policy(self, config: dict) -> dict:
|
|
channel_config = self._config_adapter._get_channel_config(config)
|
|
return {
|
|
"mode": channel_config.get("dmPolicy", "pairing"),
|
|
"allow_from": channel_config.get("allowFrom", []),
|
|
}
|