示例#1
0
def confirmation_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('order.confirmation_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  confirmation_processor)

    if not message.text:
        error()
        return
    if strings.get_string('order.confirm', language) in message.text:
        total = kwargs.get('total')
        user = userservice.get_user_by_telegram_id(user_id)
        order = orderservice.confirm_order(user_id, user.full_user_name, total)
        botutils.to_main_menu(chat_id, language,
                              strings.get_string('notifications.wait'))
        current_user = userservice.get_user_by_id(user_id)
        count_orders = current_user.count_orders
        notify_new_order(order, total, count_orders)
    elif strings.get_string('order.cancel', language) in message.text:
        userservice.clear_user_cart(user_id)
        order_canceled_message = strings.get_string('order.canceled', language)
        if 'message_id' in kwargs:
            invoice_message_id = kwargs.get('message_id')
            bot.delete_message(chat_id, invoice_message_id)
        botutils.to_main_menu(chat_id, language, order_canceled_message)
    else:
        error()
示例#2
0
def confirmation_processor(message: Message, **kwargs):
    chat_id = message.chat.id
    user_id = message.from_user.id
    language = userservice.get_user_language(user_id)

    def error():
        error_msg = strings.get_string('order.confirmation_error', language)
        bot.send_message(chat_id, error_msg)
        bot.register_next_step_handler_by_chat_id(chat_id,
                                                  confirmation_processor)

    if not message.text:
        error()
        return
    if strings.get_string('order.confirm', language) in message.text:
        total = kwargs.get('total')
        user = userservice.get_user_by_telegram_id(user_id)
        order = orderservice.confirm_order(user_id, user.full_user_name, total)
        order_success_message = strings.get_string('order.success', language)
        back_to_the_catalog(chat_id, language, order_success_message)
        notify_new_order(order, total)
    elif strings.get_string('order.cancel', language) in message.text:
        order_canceled_message = strings.get_string('order.canceled', language)
        if 'message_id' in kwargs:
            invoice_message_id = kwargs.get('message_id')
            bot.delete_message(chat_id, invoice_message_id)
        back_to_the_catalog(chat_id, language, order_canceled_message)
    else:
        error()
示例#3
0
def process_accept_policy(message):
    user_id = message.from_user.id
    chat_id = message.chat.id

    def not_allowed():
        not_allowed_message = strings.get_string('registration.not_allowed')
        remove_keyboard = keyboards.get_keyboard('remove')
        telegram_bot.send_message(chat_id,
                                  not_allowed_message,
                                  reply_markup=remove_keyboard)

    current_user = userservice.get_user_by_telegram_id(user_id)
    if current_user:
        botutils.to_main_menu(chat_id, current_user.language)
        return
    else:
        accept_text = """
        Подтвердите своё согласие с пользовательским соглашением. \nВы можете ознакомиться с пользовательским соглашением пройдя по ссылке\n
Foydalanuvchi shartnomasi bilan tanishib chiqqaningizni tasdiqlang! Foydalanuvchi shartnomasini havolani bosish orqali ko'rishingiz mumkin\n
https://delivera.uz/agreement
        """
        accept_policy = types.ReplyKeyboardMarkup(resize_keyboard=True)
        item1 = types.KeyboardButton('🤝 Я согласен(сна) / Rozilik beraman')
        accept_policy.add(item1)
        telegram_bot.send_message(chat_id,
                                  accept_text,
                                  reply_markup=accept_policy,
                                  parse_mode='HTML')
        telegram_bot.register_next_step_handler_by_chat_id(chat_id, welcome)
示例#4
0
def welcome(message):
    user_id = message.from_user.id
    chat_id = message.chat.id
    current_user = userservice.get_user_by_telegram_id(user_id)
    if current_user:
        botutils.to_main_menu(chat_id, current_user.language)
        return
    process_user_language(message)
示例#5
0
def check_language(message: Message):
    if not message.text:
        return False
    user_id = message.from_user.id
    user = userservice.get_user_by_telegram_id(user_id)
    if not user:
        return False
    language = user.language
    return strings.get_string('main_menu.language', language) in message.text and message.chat.type == 'private'
示例#6
0
def pre_checkout_order_query_handler(query: PreCheckoutQuery):
    user_id = query.from_user.id
    chat_id = user_id
    user = userservice.get_user_by_telegram_id(user_id)
    language = user.language
    total = float(query.invoice_payload)
    order = orderservice.confirm_order(user_id, user.full_user_name, total)
    bot.answer_pre_checkout_query(query.id, ok=True)
    order_success_message = strings.get_string('order.success', language)
    bot.clear_step_handler_by_chat_id(chat_id)
    back_to_the_catalog(chat_id, language, order_success_message)
    notify_new_order(order, total)
示例#7
0
def welcome(message, **kwargs):
    user_id = message.from_user.id
    chat_id = message.chat.id

    def not_allowed():
        not_allowed_message = strings.get_string('registration.not_allowed')
        remove_keyboard = keyboards.get_keyboard('remove')
        telegram_bot.send_message(chat_id, not_allowed_message, reply_markup=remove_keyboard)
    current_user = userservice.get_user_by_telegram_id(user_id)
    if current_user:
        botutils.to_main_menu(chat_id, current_user.language)
        return
    welcome_message = strings.get_string('welcome')
    language_keyboard = keyboards.get_keyboard('welcome.language')
    telegram_bot.send_message(chat_id, welcome_message, reply_markup=language_keyboard, parse_mode='HTML')
    telegram_bot.register_next_step_handler_by_chat_id(chat_id, process_user_language)