def callback_inline(call: CallbackQuery): """ Обработка inline callback запросов :param call: :return: """ # At this point, we are sure that this calendar is ours. So we cut the line by the separator of our calendar name, action, year, month, day = call.data.split(calendar_1.sep) # Processing the calendar. Get either the date or None if the buttons are of a different type date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) # There are additional steps. Let's say if the date DAY is selected, you can execute your code. I sent a message. if action == "DAY": bot.send_message( chat_id=call.from_user.id, text=f"You have chosen {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar_1}: Day: {date.strftime('%d.%m.%Y')}") elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Cancellation", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar_1}: Cancellation")
def callback_inline(call): """ Обработка inline callback запросов :param call: :return: """ data = call.data.split(";") print data if len(data) > 1: type_selected, date_new = telebot_calendar.calendar_query_handler( bot, call) print type_selected, date_new if type_selected == "DAY": bot.send_message(chat_id=call.from_user.id, text="Дата покупок выбрана - {}".format( date_new.strftime('%Y-%m-%d')), reply_markup=types.ReplyKeyboardRemove()) global date date = date_new.strftime('%Y-%m-%d') elif type_selected == "CANCEL": bot.send_message(chat_id=call.from_user.id, text="Cancellation", reply_markup=types.ReplyKeyboardRemove()) print("Cancellation") elif type_selected == "TODAY": bot.send_message(chat_id=call.from_user.id, text="Дата покупок выбрана - {}".format( datetime.today().strftime('%Y-%m-%d')), reply_markup=types.ReplyKeyboardRemove()) date = datetime.today().strftime('%Y-%m-%d')
def user_selected_date(call): user_id = call.message.chat.id name, action, year, month, day = call.data.split(calendar.sep) date = telebot_calendar.calendar_query_handler(bot, call, name, action, year, month, day) user_state = dbworker.get_user_state(user_id) if action == "DAY": if user_state == State.ADD_PRESCR_ENTER_START_DATE: # выбрали стартовую дату dbworker.add_to_session_data(user_id, {"start_date": date.strftime(date_format)}) dbworker.set_user_state(user_id, State.ADD_PRESCR_ENTER_END_DATE) bot.send_message(user_id, f"Установлена дата начала {date.strftime(date_format)}", reply_markup=ReplyKeyboardRemove()) send_enter_end_date(user_id) elif user_state == State.ADD_PRESCR_ENTER_END_DATE: # задали конечную дату dbworker.add_to_session_data(user_id, {"end_date": date.strftime(date_format)}) bot.send_message(user_id, f"Установлена дата окончания {date.strftime(date_format)}", reply_markup=ReplyKeyboardRemove()) dbworker.set_user_state(user_id, State.ADD_PRESCR_SELECT_EVENT) send_select_event(user_id) elif action == "CANCEL": if user_state == State.ADD_PRESCR_ENTER_START_DATE: # отменили стартовую дату bot.send_message(user_id, "Дата начала правила не задана (не ограниченное время в прошлом)", reply_markup=ReplyKeyboardRemove()) dbworker.set_user_state(user_id, State.ADD_PRESCR_ENTER_END_DATE) send_enter_end_date(user_id) elif user_state == State.ADD_PRESCR_ENTER_END_DATE: # отменили конечную дату bot.send_message(user_id, "Дата окончания правила не задана", reply_markup=ReplyKeyboardRemove()) dbworker.set_user_state(user_id, State.ADD_PRESCR_SELECT_EVENT) send_select_event(user_id)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar_1.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": bot.send_message( chat_id=call.from_user.id, text=f"Ты выбрал {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(), ) bot.send_message( chat_id=call.from_user.id, text= f"Твоя задача: {sql_task} Ты обещаешь её выполнить до {date.strftime('%d.%m.%Y')} \n Всё верно?", reply_markup=save_button, ) global sql_date sql_date = date.strftime('%d.%m.%Y') return sql_date print(f"{calendar_1}: Day: {date.strftime('%d.%m.%Y')}") elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Cancellation", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar_1}: Cancellation")
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": bot.send_message( chat_id=call.from_user.id, text= f"Вы выбрали {date.strftime('%d.%m.%Y')}\nСбор статистики\nПожалуйста подождите", reply_markup=ReplyKeyboardRemove(), ) account = session.query(User).filter_by( chat_id=call.from_user.id).first() vk_statistics = VkStatistics(account.vk_token, account.chat_id).by_date( time.mktime(date.timetuple())) bot.send_message(chat_id=call.from_user.id, text=vk_statistics, reply_markup=statistics_markup()) elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Отмена", reply_markup=statistics_markup(), ) print(f"{calendar}: Отмена")
def callback_inline(call: CallbackQuery): instance = instancefromlist(call.from_user.id) # At this point, we are sure that this calendar is ours. So we cut the line by the separator of our calendar name, action, year, month, day = call.data.split(calendar_1.sep) # Processing the calendar. Get either the date or None if the buttons are of a different type date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) # There are additional steps. Let's say if the date DAY is selected, you can execute your code. I sent a message. if action == "DAY": bot.send_message( chat_id=call.from_user.id, text=f"Fecha: {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar_1}: Day: {date.strftime('%d.%m.%Y')}") #encontrar la puta forma de guardar la fecha y poner aqui instance.fecha = date.strftime('%d.%m.%Y') #llamada a hora getHora(call.message, instance) elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Cancelado", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar_1}: Cancellation")
def callback_inline(call: types.CallbackQuery): if 'all_subjects' in call.data: subject_id = re.search(r'\d+$', call.data).group() return add_subject(call.message, subject_id) elif 'all_users' in call.data: user_id = re.search(r'\d+$', call.data).group() return connect_teacher_with_student(call.message, user_id) elif 'not_confirmed_schedule' in call.data: schedule_id = re.search(r'\d+$', call.data).group() return confirm_schedule(call.message, schedule_id) elif 'remove_confirmed_schedule' in call.data: schedule_id = re.search(r'\d+$', call.data).group() return confirm_schedule(call.message, schedule_id, False) elif 'time_' in call.data: lesson_time = re.search(r'(?<=_:).*', call.data).group() lesson_time = datetime.datetime.strptime(lesson_time, '%Y-%m-%d %H:%M:%S') SAVED_DATA['schedule']['lesson_time'] = lesson_time.strftime( '%Y-%m-%dT%H:%M:%SZ') create_schedule(SAVED_DATA['schedule']) bot.send_message( chat_id=call.from_user.id, text=f"Schedule created\nGo too main: /start", reply_markup=types.ReplyKeyboardRemove(), ) return name, action, year, month, day = call.data.split(calendar_1.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": if date < datetime.datetime.now(): bot.send_message( call.message.chat.id, "You can choose date older than today, try one more time") return schedule_lesson(call.message) SAVED_DATA['schedule']['users'].append(SAVED_DATA['user_id']) return clock(call.message, date) elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Cancellation \ngo too main: \start", reply_markup=types.ReplyKeyboardRemove(), ) return start(call.message)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar_1.sep) date = telebot_calendar.calendar_query_handler( bot=bot, call=call, name=name, action=action, year=year, month=month, day=day ) if action == "DAY": bot.send_message(chat_id=call.from_user.id, text=f"Вы выбрали {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(),) command_id = command.number(message.from_user.id,message.text.lower())[1] bot.send_message(call.from_user.id,commands[command_id].procedure_name) result = create_tred(commands[command_id].procedure_name,date) bot.send_message(call.from_user.id,result[1]) logi(call.from_user.id,command_id,result) elif action == "CANCEL": bot.send_message(chat_id=call.from_user.id, text="Вы решили ничего не выбирать",reply_markup=ReplyKeyboardRemove(),)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar_1.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": if date.strftime('%Y.%m.%d') < time.strftime('%Y.%m.%d'): bot.send_message( call.from_user.id, 'Похоже, ты выбрал(a) дату из прошлого. Это бот для напоминаний, а не машина времени!', reply_markup=my_calend) else: if date.strftime('%B').startswith('мар') or date.strftime( '%B').startswith('авг'): to_pr = date.strftime('%B') + 'а' to_print = date.strftime('%d ') + to_pr + date.strftime(' %Y') else: to_pr = date.strftime('%B')[:-1] + 'я' to_print = date.strftime('%d ') + to_pr + date.strftime(' %Y') bot.send_message( call.from_user.id, f"Ты выбрал(а): <b>{to_print}</b>, это правильная дата?", reply_markup=keyboard5, parse_mode='HTML') if once_or_periodic[call.from_user.id][-1] == 1: temp_date.update( {int(call.from_user.id): str(date.strftime('%d %m %Y'))}) elif once_or_periodic[call.from_user.id][-1] == 2: temp_date.update( {int(call.from_user.id): str(date.strftime('%d'))}) elif action == "BACK": if once_or_periodic[call.from_user.id][-1] == 1: bot.send_message( call.from_user.id, 'Хочешь выбрать дату на календаре или поставить таймер?', reply_markup=keyboard6) elif once_or_periodic[call.from_user.id][-1] == 2: bot.send_message(call.from_user.id, 'Ориентируемся по числам или по дням недели?', reply_markup=keyboard3)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": adult = timedelta(days=6575) if (datetime.now() - adult) > date: current_user.birth_date = date keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True, one_time_keyboard=bool(True)) keyboard.add( types.KeyboardButton(text="Send ☎", request_contact=True)) message = bot.send_message(call.message.chat.id, "Send your phone number ☎", reply_markup=keyboard) bot.register_next_step_handler(message, user_contact) else: bot.send_message(call.from_user.id, "You are under eighteen, try again") keyboard = telebot.types.InlineKeyboardMarkup() keyboard.row( telebot.types.InlineKeyboardButton("Choose", callback_data="getdate")) bot.send_message(call.from_user.id, "Choose your birthday date 📅", reply_markup=keyboard) elif action == "CANCEL": keyboard = telebot.types.InlineKeyboardMarkup() keyboard.row( telebot.types.InlineKeyboardButton("Choose", callback_data="getdate")) bot.send_message(call.from_user.id, "Please choose your birthday date 📅", reply_markup=keyboard)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(task_calendar.sep) date = telebot_calendar.calendar_query_handler( bot=bot, call=call, name=name, action=action, year=year, month=month, day=day ) if action == "DAY": new_task.date = date max_id = 0 for task in tasks_list: if task.id > max_id: max_id = task.id new_task.id = max_id + 1 tasks_list.append(new_task) saveData() bot.send_message(call.from_user.id, "Дело сохранено!") elif action == "CANCEL": bot.send_message(call.from_user.id, "Создание дела отменено.")
def callback_inline(call: CallbackQuery): """ Обработка inline callback запросов :param call: :return: """ name, action, year, month, day = call.data.split(calendar_1.sep) date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": day = f"{date.strftime('%d.%m.%Y')}" req_date[call.from_user.id] = day msg_text = '*' + state[ call.from_user. id] + ' на дату: \n' + day + '* \n Введите код главы по БК:' markup = telebot.types.InlineKeyboardMarkup() markup.add( telebot.types.InlineKeyboardButton(text='Вывести по всем', callback_data='all')) markup.add( telebot.types.InlineKeyboardButton( text='Назад', callback_data=state[call.from_user.id])) bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=msg_text, reply_markup=markup, parse_mode="Markdown") elif action == "CANCEL": state[call.from_user.id] = 'start' callback(call)
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split( calendar_1.sep) date = telebot_calendar.calendar_query_handler( bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) if action == "DAY": bot.send_message( chat_id=call.from_user.id, text=f"Вы выбрали {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(), ) bot.send_message( call.from_user.id, commands[command_id].procedure_name) result = create_tred( commands[command_id].procedure_name, date) bot.send_message(call.from_user.id, result[1]) if call.from_user.id != user.master(): bot.send_message( user.master(), 'Хозяин, для пользователя ' + user.name(call.from_user.id) + ' было выполнено задание ' + str(command_id)) elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Вы решили ничего не выбирать", reply_markup=ReplyKeyboardRemove(), )
def callback_inline(call: CallbackQuery): name, action, year, month, day = call.data.split(calendar_1.sep) # Processing the calendar. Get either the date or None if the buttons are of a different type date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) # Выбор даты if action == "DAY": task = util.update_task( date=date, task_id=EDIT_TASK_REMIND[call.from_user.id]['task_id']) bot.send_message(call.from_user.id, timer_task(task), reply_markup=mark_conf.set_remind_task(task), parse_mode='HTML') del EDIT_TASK_REMIND[call.from_user.id] elif action == "CANCEL": bot.send_message(chat_id=call.from_user.id, text="Ввод отменен", reply_markup=ReplyKeyboardRemove())
def callback_inline(call: CallbackQuery): """ Обработка inline callback запросов :param call: :return: """ # At this point, we are sure that this calendar is ours. So we cut the line by the separator of our calendar name, action, year, month, day = call.data.split(calendar.sep) # Processing the calendar. Get either the date or None if the buttons are of a different type date = telebot_calendar.calendar_query_handler(bot=bot, call=call, name=name, action=action, year=year, month=month, day=day) # There are additional steps. Let's say if the date DAY is selected, you can execute your code. I sent a message. if action == "DAY": if telebot_calendar.check_date(date): dateUsers[call.from_user.id] = f"{date.strftime('%d.%m.%Y')}" print(dateUsers[call.from_user.id]) bot.send_message( chat_id=call.from_user.id, text=f"Вы выбрали: {date.strftime('%d.%m.%Y')}", reply_markup=ReplyKeyboardRemove(), ) key = types.InlineKeyboardMarkup(row_width=3) for i in range(0, 18, 1): key_Button.append( types.InlineKeyboardButton( text=str(15 + i % 18 // 2) + ':' + str(i % 2 * 3) + '0', callback_data=str(15 + i % 18 // 2) + ':' + str(i % 2 * 3) + '0')) key_Button.append( types.InlineKeyboardButton(text="00:00", callback_data="00:00")) key_Button.append( types.InlineKeyboardButton(text="00:30", callback_data="00:30")) key_Button.append( types.InlineKeyboardButton(text="01:00", callback_data="01:00")) key_Button.reverse() for j in range(0, 7, 1): key.row(key_Button.pop(), key_Button.pop(), key_Button.pop()) bot.send_message(call.from_user.id, "Выберите время", reply_markup=key) else: bot.answer_callback_query( callback_query_id=call.id, text="Вы не можете выбрать дату из прошлого", show_alert=True) print(f"{calendar}: Day: {date.strftime('%d.%m.%Y')}") elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Бронирование отменено", reply_markup=ReplyKeyboardRemove(), ) print(f"{calendar}: Cancellation")