Esempio n. 1
0
    def get_breakfast_or_dinner_menu(update, context):
        if update.callback_query is not None:
            context.bot.answer_callback_query(update.callback_query.id)
        chat_id = update.effective_chat.id
        # send the user menu
        entered_date = ''
        if update.callback_query is None:
            entered_date = ' '.join(context.args)
        parsed_date = get_menu_query_date(entered_date)

        if parsed_date is None:
            context.bot.send_message(chat_id=chat_id,
                                     text=failed_to_parse_date_msg(entered_date))
            return

        menu = get_raw_menu(meal, parsed_date)
        hidden_cuisines = get_hidden_cuisines(update.effective_chat.id)

        if menu is None:  # if no menu, reply with no menu message
            context.bot.send_message(chat_id=chat_id,
                                     text=no_menu_msg(meal),
                                     reply_markup=start_button_kb())
        else:  # else reply user of the menu
            menu = menu_msg(parsed_date, meal, parse_menu(menu, hidden_cuisines))
            # send formatted menu to client
            context.bot.send_message(chat_id=chat_id,
                                     text=menu,
                                     parse_mode=telegram.ParseMode.HTML,
                                     reply_markup=start_button_kb())
        logging.info(f"{chat_id}: {meal} menu sent to chat")
Esempio n. 2
0
def handle_rv_count(update, context):
    numPax = get_rv_count()
    chat_id = update.effective_chat.id
    if numPax is None:
        context.bot.send_message(chat_id=chat_id,
                                 text=unable_to_retrieve_information_msg(),
                                 reply_markup=start_button_kb())
    else:
        context.bot.send_message(chat_id=chat_id,
                                 text=f'{numPax} pax',
                                 reply_markup=start_button_kb())
Esempio n. 3
0
def handle_help(update, context):
    if update.callback_query is not None:
        context.bot.edit_message_text(
            chat_id=update.effective_chat.id,
            message_id=update.callback_query.message.message_id,
            text=help_msg(),
            reply_markup=start_button_kb(),
            parse_mode=telegram.ParseMode.HTML)
        context.bot.answer_callback_query(update.callback_query.id)
    else:
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text=help_msg(),
                                 reply_markup=start_button_kb(),
                                 parse_mode=telegram.ParseMode.HTML)
Esempio n. 4
0
    def send_menu(context):
        # get menu today
        menu = get_raw_menu(meal, localized_date_today())

        if menu is None:
            return

        # get the subscribers before the broadcast
        subscribers = get_broadcast_subscribers(meal)

        logging.info(
            f"meal broadcast in progress... number of subscribers: {len(subscribers)}"
        )

        for user_id in subscribers:
            chat_id = user_id[
                0]  # extracts chat_id from nested [] from database
            hidden_cuisines = get_hidden_cuisines(chat_id)
            try:
                context.bot.send_message(chat_id=chat_id,
                                         text=menu_msg(
                                             localized_date_today(), meal,
                                             parse_menu(menu,
                                                        hidden_cuisines)),
                                         reply_markup=start_button_kb(),
                                         parse_mode='HTML')
            except Exception:
                logging.warning(
                    f"{chat_id}: exception occurs, reverting user's subscription status"
                )
                update_subscribe_setting(chat_id, meal)
                continue
            logging.info(f"{chat_id}: {meal} menu broadcast")

        logging.info("meal broadcast finished")
Esempio n. 5
0
    def handle_opt_in_inner(update, context):
        chat_id = update.effective_chat.id
        chosen_option, date = update.callback_query.data.split(".")[-2:]
        if meal == BREAKFAST:
            update_breakfast_opt_in(chat_id, date, chosen_option)
        else:
            update_dinner_opt_in(chat_id, date, chosen_option)

        # Clear markup
        context.bot.edit_message_reply_markup(
            chat_id=update.effective_chat.id,
            message_id=update.callback_query.message.message_id,
        )
        # Answer callback query (clears loading symbol)
        if update.callback_query is not None:
            context.bot.answer_callback_query(update.callback_query.id)

        # Sends thank you message
        context.bot.send_message(
            chat_id=chat_id,
            text=
            f"You have selected {capitalize(normalize(chosen_option))}. Thank you! Your response will help to reduce food wastage.",
            reply_markup=start_button_kb(),
        )