feat: add event watcher

This commit is contained in:
hh committed 2026-05-30 01:54:49 +02:00
1 parent c40e720163
commit f0afb7ec5b
11 files changed
+176 -14

No files matched your search

@@ -0,0 +1,24 @@
import re
from typing import Any
KIND_KEYWORD = "keyword"
KIND_PEER_ONLINE = "peer_online"
def match_keyword(text: str, chat_id: int, params: dict[str, Any]) -> bool:
target_chat = params.get("chat_id")
if target_chat is not None and target_chat != chat_id:
return False
pattern = params.get("pattern")
if not pattern:
return False
if params.get("regex"):
try:
return re.search(pattern, text) is not None
except re.error:
return False
return pattern.casefold() in text.casefold()
def match_peer_online(peer_id: int, params: dict[str, Any]) -> bool:
return params.get("peer_id") == peer_id