Пример #1
0
def main_menu(bot, update):
    """Show main menu"""

    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    lang = update.effective_user.language_code
    LOGGER.info(lang)

    if DBWorker.get_reg_status(update.message.chat_id) != RegStatus.COMPLETE:
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'main',
                                          'uncomplete_registration'))

        return ConversationHandler.END

    change_room_btn = KeyboardButton(
        text=ParseConfig.get_main_menu_btn(lang, 'change_room'))
    send_complaint_btn = KeyboardButton(
        text=ParseConfig.get_main_menu_btn(lang, 'send_complaint'))
    change_status_btn = KeyboardButton(
        text=ParseConfig.get_main_menu_btn(lang, 'change_status'))

    keyboard = ReplyKeyboardMarkup(
        [[change_room_btn, send_complaint_btn], [change_status_btn]],
        one_time_keyboard=True)

    update.message.reply_text(ParseConfig.get_conversations(
        lang, 'main', 'main_menu'),
                              reply_markup=keyboard)

    return MAIN_MENU
Пример #2
0
def start(bot, update):
    """/start command"""

    lang = update.effective_user.language_code
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    reg_status = DBWorker.get_reg_status(update.message.chat_id)

    if reg_status == RegStatus.NO_ROOM:
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'registration', 'no_room'))

        return ROOM
    elif reg_status == RegStatus.COMPLETE:
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'registration',
                                          'already_registered'))

        return ConversationHandler.END

    phone_btn = KeyboardButton(text=ParseConfig.get_reg_btn(
        lang, 'share_phone_number'),
                               request_contact=True)
    keyboard = ReplyKeyboardMarkup([[phone_btn]], one_time_keyboard=True)

    update.message.reply_text(ParseConfig.get_conversations(
        lang, 'registration', 'need_phone_number'),
                              reply_markup=keyboard)

    return PHONE
Пример #3
0
def phone(bot, update):
    """Get user phone"""

    lang = update.effective_user.language_code

    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    chat_id = update.message.chat_id
    phone_number = update.message.contact.phone_number

    LOGGER.info('New user: '******' | ' + str(phone_number))

    phone_number = re.sub('[()+-]', '', phone_number)

    DBWorker.reg_user(chat_id, phone_number)

    LOGGER.info('User was registered: ' + str(chat_id) + ' | ' +
                str(phone_number))

    update.message.reply_text(ParseConfig.get_conversations(
        lang, 'registration', 'get_room_number'),
                              reply_markup=ReplyKeyboardRemove())

    return ROOM
Пример #4
0
def main_menu_update_room(bot, update):
    """Update room number from main menu"""

    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    lang = update.effective_user.language_code
    if not DBWorker.update_room(update.message.chat_id, update.message.text):
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'main',
                                          'incorrect_room_number'))
        return UPDATE_ROOM

    update.message.reply_text(
        ParseConfig.get_conversations(lang, 'main', 'changed_room_number'))

    return MAIN_MENU
Пример #5
0
def help(bot, update):
    """Show help information"""

    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    lang = update.effective_user.language_code
    update.message.reply_text(ParseConfig.get_conversations(lang, 'help'))
Пример #6
0
def room(bot, update):
    """Register user room"""

    lang = update.effective_user.language_code
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)

    if not DBWorker.update_room(update.message.chat_id, update.message.text):
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'registration',
                                          'incorrect_room_number'))
        return ROOM

    update.message.reply_text(
        ParseConfig.get_conversations(lang, 'registration',
                                      'finished_registration'))

    return ConversationHandler.END
Пример #7
0
def main_menu_handler(bot, update):
    """Main menu buttons handler"""

    cmd = update.message.text
    lang = update.effective_user.language_code

    if cmd == ParseConfig.get_main_menu_btn(lang, 'change_room'):
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'main', 'get_room_number'))
        return ROOM
    elif cmd == ParseConfig.get_main_menu_btn(lang, 'send_complaint'):
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'main', 'get_complaint'))
        return COMPLAINT
    elif cmd == ParseConfig.get_main_menu_btn(lang, 'change_status'):
        update.message.reply_text(
            ParseConfig.get_conversations(lang, 'main', 'get_room_status'))
        return CHANGE_STATUS
Пример #8
0
def add_complaint(bot, update):
    """Add complaint"""

    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    lang = update.effective_user.language_code
    DBWorker.add_complaint(update.message.chat_id, update.message.text)
    update.message.reply_text(
        ParseConfig.get_conversations(lang, 'main', 'added_complaint'))

    return MAIN_MENU
Пример #9
0
def change_room_status(bot, update):
    """Change room status"""
    lang = update.effective_user.language_code
    bot.send_chat_action(chat_id=update.message.chat_id,
                         action=ChatAction.TYPING)
    DBWorker.change_room_status(DBWorker.get_room(update.message.chat_id),
                                update.message.text)
    update.message.reply_text(
        ParseConfig.get_conversations(lang, 'main',
                                      'status_successfully_changed'))

    return MAIN_MENU