tg_bot/handlers/AdminHandler.py

37 lines
1.1 KiB
Python
Raw Permalink Normal View History

2024-12-06 14:20:29 +03:00
from bot.Handler import Handler
from db.services.BookingService import BookingService
from db.services.ChatService import ChatService
from bot import FIRST
class AdminHandler(Handler):
@staticmethod
def accept_booking(update, context):
query = update.callback_query
query.answer()
variant = query.data
command, book_id = variant.split("=")
book = BookingService.get_booking_by_id(book_id)
BookingService.edit(book, "status", BookingService.STATUS_ACCEPTED)
context.bot.send_message(chat_id=book.chat_id, text="Администратор принял заявку")
admin = ChatService.get_by_chat_id(update.effective_chat.id)
name = "Неизвестный"
if hasattr(admin, "username"):
name = admin.username
elif hasattr(admin, "first_name"):
name = admin.first_name
admins = ChatService.get_admins()
for admin in admins:
context.bot.send_message(chat_id=admin.chat_id,
text="Администратор {name} принял заявку.".format(name=name))
return FIRST