Пример #1
0
def on_cancel_command(message):
    telegram_chat_id = message.chat.id
    chat = bot_backend.get_chat_by_telegram_id(telegram_chat_id, True,
                                               Chat.Sources.CANCEL)
    if bot_backend.chat_has_active_session(chat):
        session = bot_backend.get_active_session(chat)
        bot_backend.cancel_session(session)
    bot.send_message(telegram_chat_id, t('bot.messages.cancel'))
Пример #2
0
def on_soedini_command(message: tg.Message):
    telegram_chat_id = message.chat.id
    chat = bot_backend.get_chat_by_telegram_id(telegram_chat_id, True,
                                               Chat.Sources.SOEDINI)
    if not bot_backend.chat_has_active_session(chat):
        bot.send_message(chat.telegram_id, t('bot.state.error'))
        return
    session = bot_backend.get_active_session(chat)
    photos = session.photo_set.all()
    if len(photos) == 0:
        bot.send_message(chat.telegram_id, t('bot.state.error'))
        return
    bot_backend.finish_session(session)
    bot_backend.push_history_item(session)
    send_combined_image(session)
Пример #3
0
def on_photo_message(message: tg.Message):
    telegram_chat_id = message.chat.id
    if len(message.photo) == 0:
        return
    file_id = message.photo[-1].file_id
    chat = bot_backend.get_chat_by_telegram_id(telegram_chat_id, True,
                                               Chat.Sources.PHOTO)
    new_session_created = False
    if not bot_backend.chat_has_active_session(chat):
        active_session = bot_backend.create_session(chat)
        new_session_created = True
    else:
        active_session = bot_backend.get_active_session(chat)
    bot_backend.add_photo_to_session(active_session, file_id)
    if new_session_created:
        bot.send_message(chat.telegram_id, t('bot.messages.continue'))
Пример #4
0
def on_help_command(message: tg.Message):
    telegram_chat_id = message.chat.id
    chat = bot_backend.get_chat_by_telegram_id(telegram_chat_id, True,
                                               Chat.Sources.HELP)
    bot.send_message(chat.telegram_id, t('bot.messages.start'))