- Add shared proxy module (bot/utils/proxy.py) to eliminate duplicate SOCKS5 parsing - Fix AI client: escape HTML before Markdown→HTML conversion, unify timeouts, make health check optional and disabled by default, handle 429 retries - Fix ai.py: correct forwarded message handling (aiogram 3.x forward_origin), pass relevant summaries via extra_system_content - Fix dialogue.py: only respond to Astra's messages, use system context instead of prompt injection, answer on the limit message before phase transition - Fix voice.py: load Whisper model in thread pool, safe WAV path generation - Improve database.py: composite indexes, Boolean is_active, upsert file_id cache, add context cleanup helper - Update weather.py and yadisk_download.py to use shared proxy connector - Update yadisk.py: validate URL before cache clear, add download size limit, wrap sync file ops in to_thread - Reuse S3 client via lru_cache - Update setup_commands with /aiclear and /aiuser - Update README, Dockerfile (Python 3.11), docker-compose (mount models) - Pin dependency versions, remove unused httpx[socks] - Add basic pytest tests for layout converter and voice normalization
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import logging
|
|
|
|
from aiogram import Router, F
|
|
from aiogram.types import Message
|
|
|
|
from bot.utils.database import (
|
|
add_sticker_message,
|
|
ban_user_stickers,
|
|
is_user_sticker_banned,
|
|
)
|
|
from config import MODERATION_LIMIT
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = Router()
|
|
|
|
|
|
@router.message(F.sticker | F.animation)
|
|
async def handle_sticker_or_gif(message: Message):
|
|
user_id = message.from_user.id
|
|
chat_id = message.chat.id
|
|
|
|
if await is_user_sticker_banned(user_id, chat_id):
|
|
try:
|
|
await message.delete()
|
|
logger.info(
|
|
"Deleted sticker/gif from banned user | user=%d chat=%d",
|
|
user_id,
|
|
chat_id,
|
|
)
|
|
except Exception as exc:
|
|
logger.warning("Could not delete sticker/gif: %s", exc)
|
|
return
|
|
|
|
count = await add_sticker_message(user_id, chat_id)
|
|
logger.debug("Sticker/gif count | user=%d chat=%d count=%d", user_id, chat_id, count)
|
|
|
|
if count >= MODERATION_LIMIT:
|
|
await ban_user_stickers(user_id, chat_id)
|
|
logger.info(
|
|
"Sticker/gif ban triggered | user=%d chat=%d count=%d",
|
|
user_id,
|
|
chat_id,
|
|
count,
|
|
)
|
|
await message.answer(
|
|
f"⚠️ {message.from_user.full_name}, вы превысили лимит стикеров/GIF!\n"
|
|
"Отправка стикеров и GIF ограничена на 5 минут.",
|
|
parse_mode=None,
|
|
)
|