vk_chat_bot/handlers/action.py
Kirill Kirilenko 0894e3b775 Реорганизация проекта.
Обработчики разделены на несколько модулей.
2025-08-28 03:21:48 +03:00

34 lines
986 B
Python

from vkbottle.bot import Message
import database
from messages import *
from labeler import labeler
@labeler.chat_message(action=['chat_invite_user', 'chat_invite_user_by_link'])
async def user_join_handler(message: Message):
chat_id = message.peer_id
chat = database.create_chat_if_not_exists(chat_id)
if chat['active'] == 0:
return
if message.action.type == 'chat_invite_user_by_link':
user_id = message.from_id
first_join = True
else:
user_id = message.action.member_id
first_join = (user_id != message.from_id)
user_info = (await message.ctx_api.users.get(user_ids=[user_id]))[0]
if user_id < 0:
return
if first_join:
response = chat['greeting_join'] or MESSAGE_DEFAULT_GREETING_JOIN
else:
response = chat['greeting_rejoin'] or MESSAGE_DEFAULT_GREETING_REJOIN
response = response.format(name=f'@id{user_id} ({user_info.first_name})')
await message.answer(response)