vk_chat_bot/tg/handlers/default.py
2025-10-25 02:19:35 +03:00

44 lines
1.2 KiB
Python

from aiogram import Router, F
from aiogram.types import Message
from aiogram.enums.content_type import ContentType
import utils
import tg.tg_database as database
router = Router()
ACCEPTED_CONTENT_TYPES: list[ContentType] = [
ContentType.TEXT,
ContentType.ANIMATION,
ContentType.AUDIO,
ContentType.DOCUMENT,
ContentType.PAID_MEDIA,
ContentType.PHOTO,
ContentType.STICKER,
ContentType.STORY,
ContentType.VIDEO,
ContentType.VIDEO_NOTE,
ContentType.VOICE,
ContentType.CHECKLIST,
ContentType.CONTACT,
ContentType.POLL,
ContentType.VENUE,
ContentType.LOCATION
]
@router.message(F.content_type.in_(ACCEPTED_CONTENT_TYPES))
async def any_message_handler(message: Message):
chat_id = message.chat.id
chat = database.DB.create_chat_if_not_exists(chat_id)
if chat['active'] == 0:
return
# Игнорировать ботов
if message.from_user.is_bot:
return
user_id = message.from_user.id
database.DB.create_user_if_not_exists(chat_id, user_id)
database.DB.user_set_last_message(chat_id, user_id, utils.posix_time())
database.DB.user_increment_messages(chat_id, user_id)