def calendar_test(msg: types.Message):
    inline_calendar.init(msg.from_user.id, datetime.date.today(),
                         datetime.date(year=2018, month=11, day=1),
                         datetime.date(year=2019, month=4, day=1))
    bot.send_message(msg.from_user.id,
                     text='test',
                     reply_markup=inline_calendar.get_keyboard(
                         msg.from_user.id))
示例#2
0
                    def calendar_test(message):
                        inline_calendar.init(
                            message.from_user.id, datetime.date.today(),
                            datetime.date(year=2019, month=1, day=1),
                            datetime.date(year=2020, month=12, day=31))

                        msg = bot.send_message(
                            message.from_user.id,
                            text='Пожалуйста, выберете дату.',
                            reply_markup=inline_calendar.get_keyboard(
                                message.from_user.id))
示例#3
0
def calendar_callback_handler(call):
    print(call)
    bot.answer_callback_query(call.id)
    #print(bot.answer_callback_query(q.id))
    #print(q.id)
    print(call.data)
    try:
        return_data = inline_calendar.handler_callback(call.from_user.id, call.data)
        print(return_data)
        print(call.from_user.id)
        if return_data is None:
            bot.edit_message_reply_markup(chat_id=call.from_user.id, message_id=call.message.message_id,
                                          reply_markup=inline_calendar.get_keyboard(call.from_user.id))
        else:
            picked_data = return_data
            bot.send_message(text= "Вы записанны. Ваша дата записи:", chat_id=call.from_user.id)
            bot.send_message(text=picked_data, chat_id=call.from_user.id)

    except inline_calendar.WrongChoiceCallbackException:
        bot.edit_message_text(text='Ошибка', chat_id=call.from_user.id, message_id=call.message.message_id,
                              reply_markup=inline_calendar.get_keyboard(call.from_user.id))
def calendar_callback_handler(q: types.CallbackQuery):
    bot.answer_callback_query(q.id)

    try:
        return_data = inline_calendar.handler_callback(q.from_user.id, q.data)
        if return_data is None:
            bot.edit_message_reply_markup(
                chat_id=q.from_user.id,
                message_id=q.message.message_id,
                reply_markup=inline_calendar.get_keyboard(q.from_user.id))
        else:
            picked_data = return_data
            bot.edit_message_text(text=picked_data,
                                  chat_id=q.from_user.id,
                                  message_id=q.message.message_id,
                                  reply_markup=inline_calendar.get_keyboard(
                                      q.from_user.id))

    except inline_calendar.WrongChoiceCallbackException:
        bot.edit_message_text(text='Wrong choice',
                              chat_id=q.from_user.id,
                              message_id=q.message.message_id,
                              reply_markup=inline_calendar.get_keyboard(
                                  q.from_user.id))
示例#5
0
                    def calendar_callback_handler(call):
                        bot.answer_callback_query(call.id)
                        try:
                            print('try')
                            return_data = inline_calendar.handler_callback(
                                call.from_user.id, call.data)
                            if return_data is None:
                                bot.edit_message_reply_markup(
                                    chat_id=call.from_user.id,
                                    message_id=call.message.message_id,
                                    reply_markup=inline_calendar.get_keyboard(
                                        call.from_user.id))
                            else:
                                picked_data = return_data
                                bot.send_message(text=picked_data,
                                                 chat_id=call.from_user.id)

                        except inline_calendar.WrongChoiceCallbackException:
                            bot.edit_message_text(
                                text='Ошибка',
                                chat_id=call.from_user.id,
                                message_id=call.message.message_id,
                                reply_markup=inline_calendar.get_keyboard(
                                    call.from_user.id))
示例#6
0
def callback_inline(call):
    """ Handle all callbacks """
    if str(call.data) == '273':
        utility.update(
            {str(call.message.chat.id) + 'place_code': str(call.data)})
        bot.send_message(call.message.chat.id,
                         f'Good! Now, please tell me the date of departure🖊')
        inline_calendar.init(
            call.message.chat.id, datetime.date.today(), datetime.date.today(),
            datetime.date.today() + datetime.timedelta(days=365))
        bot.send_message(call.message.chat.id,
                         text='Chosen date',
                         reply_markup=inline_calendar.get_keyboard(
                             call.message.chat.id))
        utility.update({str(call.message.chat.id) + 'date_from_check': '1'})
    if str(call.data) == '272':
        utility.update(
            {str(call.message.chat.id) + 'place_code': str(call.data)})
        date_example = date_plus_day(call.message)
        bot.send_message(call.message.chat.id,
                         f'Good! Now, please tell me the date of departure🖊')
        inline_calendar.init(
            call.message.chat.id, datetime.date.today(), datetime.date.today(),
            datetime.date.today() + datetime.timedelta(days=365))
        bot.send_message(call.message.chat.id,
                         text='Chosen date',
                         reply_markup=inline_calendar.get_keyboard(
                             call.message.chat.id))
        utility.update({str(call.message.chat.id) + 'date_from_check': '1'})
    try:
        if int(call.data) == utility.get(
                str(call.message.chat.id) + 'tariff1')[2]:
            print('Callback accepted1')
            utility.update({
                str(call.message.chat.id) + 'tariff_risk_amount':
                utility.get(str(call.message.chat.id) + 'tariff1')[6]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_payment':
                utility.get(str(call.message.chat.id) + 'tariff1')[3]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_name':
                utility.get(str(call.message.chat.id) + 'tariff1')[1]
            })
            bot.send_message(
                call.message.chat.id,
                'Good choice! You will now need your passport. \nWrite your name ✍'
            )
            dbworker.set_state(call.message.chat.id,
                               config.States.S_NAME_INPUT.value)
        if int(call.data) == utility.get(
                str(call.message.chat.id) + 'tariff2')[2]:
            print('Callback accepted2')
            utility.update({
                str(call.message.chat.id) + 'tariff_risk_amount':
                utility.get(str(call.message.chat.id) + 'tariff2')[6]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_payment':
                utility.get(str(call.message.chat.id) + 'tariff2')[3]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_name':
                utility.get(str(call.message.chat.id) + 'tariff2')[1]
            })
            bot.send_message(
                call.message.chat.id,
                'Good choice! You will now need your passport. \nWrite your name ✍'
            )
            dbworker.set_state(call.message.chat.id,
                               config.States.S_NAME_INPUT.value)
        if int(call.data) == utility.get(
                str(call.message.chat.id) + 'tariff3')[2]:
            print('Callback accepted3')
            utility.update({
                str(call.message.chat.id) + 'tariff_risk_amount':
                utility.get(str(call.message.chat.id) + 'tariff3')[6]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_payment':
                utility.get(str(call.message.chat.id) + 'tariff3')[3]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_name':
                utility.get(str(call.message.chat.id) + 'tariff3')[1]
            })
            bot.send_message(
                call.message.chat.id,
                'Good choice! You will now need your passport. \nWrite your name ✍'
            )
            dbworker.set_state(call.message.chat.id,
                               config.States.S_NAME_INPUT.value)
        if int(call.data) == utility.get(
                str(call.message.chat.id) + 'tariff4')[2]:
            print('Callback accepted4')
            utility.update({
                str(call.message.chat.id) + 'tariff_risk_amount':
                utility.get(str(call.message.chat.id) + 'tariff4')[6]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_payment':
                utility.get(str(call.message.chat.id) + 'tariff4')[3]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_name':
                utility.get(str(call.message.chat.id) + 'tariff4')[1]
            })
            bot.send_message(
                call.message.chat.id,
                'Good choice! You will now need your passport. \nWrite your name ✍'
            )
            dbworker.set_state(call.message.chat.id,
                               config.States.S_NAME_INPUT.value)
        if int(call.data) == utility.get(
                str(call.message.chat.id) + 'tariff5')[2]:
            print('Callback accepted5')
            utility.update({
                str(call.message.chat.id) + 'tariff_risk_amount':
                utility.get(str(call.message.chat.id) + 'tariff5')[6]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_payment':
                utility.get(str(call.message.chat.id) + 'tariff5')[3]
            })
            utility.update({
                str(call.message.chat.id) + 'tariff_name':
                utility.get(str(call.message.chat.id) + 'tariff5')[1]
            })
            bot.send_message(
                call.message.chat.id,
                'Good choice! You will now need your passport. \nWrite your name ✍'
            )
            dbworker.set_state(call.message.chat.id,
                               config.States.S_NAME_INPUT.value)
    except TypeError:
        pass
示例#7
0
def calendar_callback_handler(q: types.CallbackQuery):
    """ Handle all inline calendars """
    if utility.get(str(q.from_user.id) + 'date_from_check') == '1':
        bot.answer_callback_query(q.id)
        try:
            return_data = inline_calendar.handler_callback(
                q.from_user.id, q.data)
            if return_data is None:
                bot.edit_message_reply_markup(
                    chat_id=q.from_user.id,
                    message_id=q.message.message_id,
                    reply_markup=inline_calendar.get_keyboard(q.from_user.id))
            else:
                picked_data = return_data
                bot.edit_message_text(
                    text=picked_data,
                    chat_id=q.from_user.id,
                    message_id=q.message.message_id,
                    reply_markup=inline_calendar.get_keyboard(q.from_user.id))
                utility.update(
                    {str(q.from_user.id) + 'date_from': picked_data})
                bot.send_message(
                    q.from_user.id,
                    'I\'ll remember, now tell me the return date🏠')
                inline_calendar.init(
                    q.from_user.id, datetime.date.today(),
                    datetime.date.today(),
                    datetime.date.today() + datetime.timedelta(days=365))
                bot.send_message(q.from_user.id,
                                 text='Chosen date',
                                 reply_markup=inline_calendar.get_keyboard(
                                     q.from_user.id))
                utility.update({str(q.from_user.id) + 'date_to_check': '1'})
                utility.update({str(q.from_user.id) + 'date_from_check': '0'})
        except inline_calendar.WrongChoiceCallbackException:
            bot.edit_message_text(text='Wrong choice',
                                  chat_id=q.from_user.id,
                                  message_id=q.message.message_id,
                                  reply_markup=inline_calendar.get_keyboard(
                                      q.from_user.id))
    if utility.get(str(q.from_user.id) + 'date_to_check') == '1':
        bot.answer_callback_query(q.id)
        try:
            return_data = inline_calendar.handler_callback(
                q.from_user.id, q.data)
            if return_data is None:
                bot.edit_message_reply_markup(
                    chat_id=q.from_user.id,
                    message_id=q.message.message_id,
                    reply_markup=inline_calendar.get_keyboard(q.from_user.id))
            else:
                picked_data = return_data
                utility.update({str(q.from_user.id) + 'date_to': picked_data})
                bot.edit_message_text(
                    text=picked_data,
                    chat_id=q.from_user.id,
                    message_id=q.message.message_id,
                    reply_markup=inline_calendar.get_keyboard(q.from_user.id))
                asking_target(q)

        except inline_calendar.WrongChoiceCallbackException:
            bot.edit_message_text(text='Wrong choice',
                                  chat_id=q.from_user.id,
                                  message_id=q.message.message_id,
                                  reply_markup=inline_calendar.get_keyboard(
                                      q.from_user.id))