예제 #1
0
def choose_hour(update, context):
    i = 0
    while i < len(HOURS):

        if update.message.text in HOURS[i]:
            check = sess.query(Reservation).filter_by(
                day=date(2019, int(userState[update.message.chat.id]['month']),
                         int(userState[update.message.chat.id]['day'])),
                slot=update.message.text).first()
            if check is None:
                res = Reservation(
                    user_id=update.message.chat.id,
                    day=date(2019,
                             int(userState[update.message.chat.id]['month']),
                             int(userState[update.message.chat.id]['day'])),
                    slot=update.message.text)
                sess.add(res)
                sess.commit()
                userState[update.message.chat.id] = {}
                update.message.reply_text('Time reserved successfully.')
                return True
            else:
                update.message.reply_text('This hour is already reserved.')
                return False
        i += 1
    update.message.reply_text('This hour is not available to reserve.')
    return False
예제 #2
0
def subscribe_user_to_waiting_list(context, user_id):
    chosen_day = date(YEAR, int(context.user_data['month']), int(context.user_data['day']))
    waitinglist = sess.query(WaitingList).filter(
        WaitingList.user_id == user_id,
        WaitingList.day == chosen_day,
    ).first()
    if waitinglist:
        return  'You are already in Waiting list for `' + chosen_day.strftime("%Y-%m-%d") + '`'
    new_waitinglist = WaitingList(
        user_id=user_id,
        day=chosen_day,
    )
    sess.add(new_waitinglist)
    sess.commit()
    return  'You are added to Waiting list successfully for `' + chosen_day.strftime("%Y-%m-%d") + '`. The bot will notify you if any reservation on this day is cancelled'
예제 #3
0
def start(update, context):
    user = User(id_=update.message.chat.id,
                telegramID=update.message.chat.username)
    check = sess.query(User).get(update.message.chat.id)
    if check is None:
        sess.add(user)
        sess.commit()
    update.message.reply_text(
        'Welcome to BBQ reserver telegram bot.\n'
        'By can book a time slot for barbecue zone in Innopolis city, Republic Tatarstan!\n\n'
        'Main features of bot:\n'
        '- view available time slots for barbecue zone;\n'
        '- a book time slot for barbecue zone;\n'
        '- cancel booking;\n'
        'Send /cancel if you want to return to the main menu(just in case)',
        reply_markup=ReplyKeyboardMarkup(main_menu, resize_keyboard=True))
예제 #4
0
def choose_hour(update, context):
    hours = get_hours()
    if update.message.text in hours:
        splitted_time = update.message.text.split(':')
        chosen_day = datetime(YEAR, int(context.user_data['month']), int(context.user_data['day']), int(splitted_time[0]), int(splitted_time[1]), 0)
        check = sess.query(Reservation).filter_by(
            day=chosen_day,
            slot=update.message.text
        ).first()
        if check is None:
            res = Reservation(
                user_id=update.message.chat.id,
                day=chosen_day,
                slot=update.message.text
            )
            sess.add(res)
            waitinglist = sess.query(WaitingList).filter(
                WaitingList.user_id == update.message.chat.id,
                WaitingList.day == date(chosen_day.year, chosen_day.month, chosen_day.day),
            ).first()
            if waitinglist:
                sess.delete(waitinglist)
            sess.commit()

            text = 'Time `' + chosen_day.strftime("%Y-%m-%d %H:%M") + '` reserved successfully'
            update.message.reply_text(text, reply_markup=ReplyKeyboardMarkup(base.main_menu, resize_keyboard=True), parse_mode=ParseMode.MARKDOWN)
            return ConversationHandler.END
        update.message.reply_text('This hour is already reserved')
    elif update.message.text == 'Back':
        context.user_data['wrong_day'] = True
        choose_month(update, context)
        return DAY
    elif update.message.text == 'Subscribe to waiting list':
        response = subscribe_user_to_waiting_list(context, update.message.chat.id)
        update.message.reply_text(response, parse_mode=ParseMode.MARKDOWN)
        base.cancel(update, context)
        return ConversationHandler.END
    elif update.message.text == 'Cancel':
        base.cancel(update, context)
        return ConversationHandler.END
    else:
        context.user_data['wrong_hour'] = True
        update.message.reply_text('Wrong hour')
    choose_day(update, context)
    return HOUR