新增BlueBubbles适配器全套核心工具类与服务,包含会话管理、消息去重、Webhook验证、缓存系统、账号配置解析、聊天消息处理等完整功能模块,支持iMessage消息收发、群管理、反应特效、语音合成等能力,提供完善的健康检查与配置校验流程。
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
class ActionGate:
|
|
ACTIONS_REQUIRING_PRIVATE_API = {
|
|
"unsend",
|
|
"rename_group",
|
|
"set_group_icon",
|
|
"add_participant",
|
|
"remove_participant",
|
|
"leave_group",
|
|
}
|
|
|
|
ACTIONS_DISABLED_ON_MACOS26 = {"edit"}
|
|
|
|
def __init__(self) -> None:
|
|
self._private_api_available: bool | None = None
|
|
self._is_macos_26_or_higher: bool | None = None
|
|
|
|
def set_private_api_available(self, available: bool) -> None:
|
|
self._private_api_available = available
|
|
|
|
def set_macos_26_or_higher(self, is_26_plus: bool) -> None:
|
|
self._is_macos_26_or_higher = is_26_plus
|
|
|
|
def is_action_allowed(self, action: str, context: dict[str, Any] | None = None) -> bool:
|
|
if action in self.ACTIONS_REQUIRING_PRIVATE_API:
|
|
if self._private_api_available is not True:
|
|
return False
|
|
|
|
if action in self.ACTIONS_DISABLED_ON_MACOS26:
|
|
if self._is_macos_26_or_higher:
|
|
return False
|
|
|
|
return True
|
|
|
|
def get_available_actions(self) -> list[str]:
|
|
actions: list[str] = ["send", "send_media", "react", "reply"]
|
|
if self._private_api_available:
|
|
actions.extend(
|
|
[
|
|
"unsend",
|
|
"rename_group",
|
|
"set_group_icon",
|
|
"add_participant",
|
|
"remove_participant",
|
|
"leave_group",
|
|
]
|
|
)
|
|
if not self._is_macos_26_or_higher:
|
|
actions.append("edit")
|
|
return sorted(actions)
|