def list_watchlists(update, context): user = get_user(update.effective_user.id) watchlists = get_watchlists(user) if not watchlists: return restart(update, context) reply_markup = get_watchlists_keyboard(watchlists) update.message.reply_text('Your watchlists:', reply_markup=reply_markup) return SELECT_WATCHLIST
def remove_watchlist(update, context): user = get_user(update.effective_user.id) watchlists = get_watchlists(user) if not watchlists: return restart(update, context) reply_markup = get_watchlists_keyboard(watchlists) update.message.reply_text('Select watchlist to remove:', reply_markup=reply_markup) return SELECT_WATCHLIST_FOR_REMOVAL
def list_matching_cars(update, context): user = get_user(update.effective_user.id) watchlists = get_watchlists(user) if not watchlists: return restart(update, context) reply_markup = get_watchlists_keyboard(watchlists) update.message.reply_text('Select watchlist to list matching cars:', reply_markup=reply_markup) return LIST_MATCHING_CARS
def edit_watchlist(update, context): context.user_data.pop('find_car', None) user = get_user(update.effective_user.id) watchlists = get_watchlists(user) if not watchlists: return restart(update, context) watchlists_keyboard = get_watchlists_keyboard(watchlists) update.message.reply_text('Select watchlist to edit:', reply_markup=watchlists_keyboard) return SELECT_WATCHLIST_FOR_EDITING
def save_watchlist(update, context): query = update.callback_query try: query.answer() user = get_user(update.effective_user.id) watchlist = build_watchlist(user, context.user_data['watchlist']) watchlist['userId'] = user['_id'] if context.user_data.get('watchlist_id'): result = watchlist_edited(query, watchlist, context) else: result = watchlist_added(query, watchlist) except: query.bot.send_message(query.message.chat_id, 'An error occurred when adding watchlist', parse_mode=ParseMode.MARKDOWN) return result
def car_query_inputted(update, context): query = update.callback_query try: query.answer() query.bot.send_message(query.message.chat_id, f'Searching {HOURGLASS_ICON} Please wait', parse_mode=ParseMode.MARKDOWN) # FIXME redundant build_watchlist call user = get_user(update.effective_user.id) watchlist = build_watchlist(user, context.user_data['watchlist']) find_and_print_cars(update, query, watchlist) except: query.bot.send_message(query.message.chat_id, 'An error occurred when finding watchlist', parse_mode=ParseMode.MARKDOWN) return offer_save_watchlist(update, context)
def back_confirm_watchlist_details(update, context): query = update.callback_query user = get_user(update.effective_user.id) watchlist = build_watchlist(user, context.user_data['watchlist']) if context.user_data.get('find_car'): confirm_details_keyboard = get_confirm_details_keyboard('Find car') else: confirm_details_keyboard = get_confirm_details_keyboard( 'Save watchlist') if query: query.answer() query.bot.send_message(query.message.chat_id, print_watchlist(watchlist), parse_mode=ParseMode.MARKDOWN) query.bot.send_message(query.message.chat_id, 'Please choose:', reply_markup=confirm_details_keyboard) return INPUT_WATCHLIST_DETAILS_CONFIRM update.message.reply_text(print_watchlist(watchlist), parse_mode=ParseMode.MARKDOWN) update.message.reply_text('Please choose:', reply_markup=confirm_details_keyboard) return INPUT_WATCHLIST_DETAILS_CONFIRM
def watchlist_model_inputted(update, context): query = update.callback_query model = query.data if model == '/cancel': return cancel_action(query, 'Adding watchlist cancelled') query.answer() context.user_data['watchlist']['model'] = model user = get_user(update.effective_user.id) watchlist = build_watchlist(user, context.user_data['watchlist']) if context.user_data.get('find_car'): confirm_details_keyboard = get_confirm_details_keyboard('Find car') else: confirm_details_keyboard = get_confirm_details_keyboard( 'Save watchlist') query.bot.send_message(query.message.chat_id, print_watchlist(watchlist), parse_mode=ParseMode.MARKDOWN) query.bot.send_message(query.message.chat_id, 'Please choose:', reply_markup=confirm_details_keyboard) return INPUT_WATCHLIST_DETAILS_CONFIRM
def feedback_inputted(update, context): user = get_user(update.effective_user.id) insert_feedback(user, update.message.text) update.message.reply_text('Thank you! We\'re on it.') return ConversationHandler.END