Files
PrimoGuardBot/database/__init__.py

40 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Database модуль для работы с банвордами в SQLite.
Использует SQLAlchemy ORM для async работы с БД.
Структура:
- models.py: Модели таблиц (BanWord, TempBanWord, WhitelistWord, Admin, Setting, SpamStat)
- database.py: Подключение к БД через SQLAlchemy
- repository.py: CRUD операции через ORM
- manager.py: Высокоуровневый API для handlers/middleware
Usage:
from database import get_manager, BanWordType
# Инициализация
manager = get_manager()
await manager.init()
# Добавление банворда
await manager.add_banword("спам", BanWordType.SUBSTRING, added_by=123)
# Проверка (из кэша - быстро)
words = manager.get_banwords_cached(BanWordType.SUBSTRING)
if "спам" in text and "спам" in words:
await manager.log_spam(...)
# Режим тишины
await manager.set_silence_mode(minutes=30)
if await manager.is_silence_active():
# Удаляем всё
"""
from .models import *
from .database import *
from .repository import *
from .manager import *