该提交新增了基于BlueBubbles的iMessage渠道插件,支持单聊和群组消息,包含文本、图片、语音、文件和视频消息收发,支持消息编辑、撤回、回复、 reactions和输入状态提示,同时实现了账号配置、安全校验、配对授权、消息格式化与分片等完整功能。
39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import time
|
|
|
|
|
|
class EchoCache:
|
|
def __init__(self, ttl_ms: int = 10_000):
|
|
self._cache: dict[str, float] = {}
|
|
self._ttl = ttl_ms
|
|
|
|
def remember(self, chat_guid: str, text: str) -> None:
|
|
key = self._build_key(chat_guid, text)
|
|
self._cache[key] = time.monotonic()
|
|
|
|
def is_echo(self, chat_guid: str, text: str) -> bool:
|
|
key = self._build_key(chat_guid, text)
|
|
ts = self._cache.get(key)
|
|
if ts and (time.monotonic() - ts) * 1000 < self._ttl:
|
|
return True
|
|
return False
|
|
|
|
def cleanup(self) -> None:
|
|
now = time.monotonic()
|
|
expired = [
|
|
k for k, ts in self._cache.items()
|
|
if (now - ts) * 1000 >= self._ttl
|
|
]
|
|
for k in expired:
|
|
del self._cache[k]
|
|
|
|
def clear(self) -> None:
|
|
self._cache.clear()
|
|
|
|
@staticmethod
|
|
def _build_key(chat_guid: str, text: str) -> str:
|
|
raw = f"{chat_guid}:{text}"
|
|
return hashlib.sha256(raw.encode()).hexdigest()[:16]
|