def confirm_watchlist_details(update, context): query = update.callback_query user_answer = query.data if user_answer == '/cancel' or user_answer == 'No': return cancel_action(query, 'Adding watchlist cancelled') if user_answer == 'Save watchlist' or user_answer == 'Yes': return save_watchlist(update, context) if user_answer == 'Find car': return car_query_inputted(update, context) try: query.answer() options = ['Add year', 'Add max mileage', 'Add max price'] buttons = create_buttons(options) buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) options_keyboard = create_menu(buttons, n_cols=3) query.bot.send_message(query.message.chat_id, 'Please choose:', reply_markup=options_keyboard) except: query.bot.send_message(query.message.chat_id, 'An error occurred when listing cars', parse_mode=ParseMode.MARKDOWN) return INPUT_CAR_PARAMETERS
def get_confirm_details_keyboard(first_button): options = [first_button, 'Add more details'] buttons = create_buttons(options) buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) confirm_details_keyboard = create_menu(buttons, n_cols=2) return confirm_details_keyboard
def offer_save_watchlist(update, context): query = update.callback_query buttons = create_buttons(['Yes', 'No']) answers_keyboard = create_menu(buttons, n_cols=2) query.bot.send_message( query.message.chat_id, 'Would you like to get notifications about new such cars?', reply_markup=answers_keyboard) return INPUT_WATCHLIST_DETAILS_CONFIRM
def input_watchlist(update, context): buttons = create_buttons(list(LETTER_MAKE_MODEL.keys())) buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) letter_keyboard = create_menu(buttons, n_cols=4) reply_func = get_reply_func(update) reply_func('Select make first letter:', reply_markup=letter_keyboard) return INPUT_WATCHLIST_LETTER
def get_watchlists_keyboard(watchlists): keyboard = create_buttons( watchlists, button_getter=lambda x: [x], caption_getter=print_watchlist_short, value_getter=lambda x: str(x['_id']), ) keyboard.append([InlineKeyboardButton('/cancel', callback_data='/cancel')]) return InlineKeyboardMarkup(keyboard)
def list_models(query, models, has_more_models=False): buttons = create_buttons(models) if has_more_models: buttons.append( InlineKeyboardButton(text='more...', callback_data='more')) result = INPUT_WATCHLIST_MORE_MODELS else: buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) result = INPUT_WATCHLIST_MODEL model_keyboard = create_menu(buttons, n_cols=2) query.bot.send_message(query.message.chat_id, 'Select model:', reply_markup=model_keyboard) return result
def watchlist_letter_inputted(update, context): query = update.callback_query letter = query.data if letter == '/cancel': return cancel_action(query, 'Adding watchlist cancelled') query.answer() context.user_data['letter'] = letter buttons = create_buttons(list(LETTER_MAKE_MODEL[letter].keys())) buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) make_keyboard = create_menu(buttons, n_cols=2) query.bot.send_message(query.message.chat_id, 'Select make:', reply_markup=make_keyboard) return INPUT_WATCHLIST_MAKE
def get_years_keyboard(): years = [x for x in range(2000, 2021)] buttons = create_buttons(years) buttons.append( InlineKeyboardButton(text='/cancel', callback_data='/cancel')) return create_menu(buttons, n_cols=3)