Initial commit

This commit is contained in:
2026-05-13 23:38:18 +02:00
commit 8b053a7adb
21 changed files with 6642 additions and 0 deletions

51
persistence.py Normal file
View File

@@ -0,0 +1,51 @@
import json
import os
import bot_state as state
from config import BACKUP_IDS_FILE, BLACKLISTED_WORDS_FILE, CONFIRMED_USERS_FILE
def load_backup_ids() -> None:
if not os.path.exists(BACKUP_IDS_FILE):
return
try:
with open(BACKUP_IDS_FILE) as f:
data = json.load(f)
state.backup_hashes = data if isinstance(data, dict) else {}
except Exception:
state.backup_hashes = {}
def save_backup_ids() -> None:
try:
with open(BACKUP_IDS_FILE, "w") as f:
json.dump(state.backup_hashes, f)
except Exception:
pass
def load_confirmed_users() -> None:
if not os.path.exists(CONFIRMED_USERS_FILE):
return
try:
with open(CONFIRMED_USERS_FILE) as f:
state.confirmed_users = set(json.load(f))
except Exception:
state.confirmed_users = set()
def save_confirmed_users() -> None:
try:
with open(CONFIRMED_USERS_FILE, "w") as f:
json.dump(list(state.confirmed_users), f)
except Exception:
pass
def load_blacklist() -> None:
if not os.path.exists(BLACKLISTED_WORDS_FILE):
return
try:
with open(BLACKLISTED_WORDS_FILE, encoding="utf-8") as f:
state.blacklisted_words = [ln.strip().lower() for ln in f if ln.strip()]
except Exception:
state.blacklisted_words = []