Пример #1
0
def next_back(message, back_to):
    """
    :param message: Message object with data about user, chat, etc type <class>
    :param back_to: Back to location (main menu, author/theme list) type <str>
    :return: return nothing
    """
    state_user = s.get_full_state(message.from_user.id)
    # If state equally starting or author - don't action
    if state_user[0] == state['st'] or state_user[0] == state['at']:
        return
    if state_user[0] == state['th']:   # If state equally theme - getting theme list
        buttons = db.get_info_by_choice(state_user[0])
    else:   # If state equally all or author_choice or theme_choice - getting buttons by condition
        table = state_user[0].split('_')[0]   # [all, theme, author]
        condition = state_user[3] if len(state_user) == 4 else ''  # [author name, theme name, empty string]
        buttons = db.get_articles(table, condition)

    category = state_user[3] if len(state_user) == 4 else None   # Create category buttons or None
    if message.text == 'Далее':
        bot.send_message(
            message.from_user.id, text='Далее', parse_mode='markdown',
            reply_markup=pre_modified_button(buttons, back_to, state_user[1] + 20, state_user[2] + 20))
        s.change_state(message.from_user.id, state_user[0],
                       '{}:{}'.format(state_user[1] + 20, state_user[2] + 20), category)
    if message.text == 'Назад':
        start = state_user[1] - 20 if state_user[1] - 20 >= 0 else 0
        finish = state_user[2] - 20 if state_user[2] - 20 >= 20 else 20
        bot.send_message(message.from_user.id, text='Назад', parse_mode='markdown',
                         reply_markup=pre_modified_button(buttons, back_to, start, finish))
        s.change_state(message.from_user.id, state_user[0], '{}:{}'.format(start, finish), category)
Пример #2
0
def article_by(message, state_type, table, back_to, mess):
    """
    :param message: Message object with data about user, chat, etc type <class>
    :param state_type: New user state type <str>
    :param table: The Table from which data will be received type <str>
    :param back_to: Section where the user will be returned type <str>
    :param mess: Message to show to user type <str>
    """
    bot.send_message(message.from_user.id, mess.format(message.text), parse_mode='markdown',
                     reply_markup=pre_modified_button(db.get_articles(table, message.text), back_to))
    s.change_state(message.from_user.id, state_type, '0:20', message.text)
Пример #3
0
def courses_handler(message: telebot.types.Message):
    bot.send_message(message.from_user.id, hello_courses_mes, parse_mode='markdown',
                     reply_markup=pre_modified_button(db.get_info_by_choice('courses'), first_level_back))
    s.change_state(message.from_user.id, state['cr'])
Пример #4
0
def other_articles_handler(message: telebot.types.Message):
    bot.send_message(message.from_user.id, hello_other_mes, parse_mode='markdown',
                     reply_markup=pre_modified_button(db.get_info_by_choice('other_content'), first_level_back))
    s.change_state(message.from_user.id, state['ot'])
Пример #5
0
def all_articles_handler(message: telebot.types.Message):
    bot.send_message(message.from_user.id, hello_all_mes, parse_mode='markdown',
                     reply_markup=pre_modified_button(db.get_articles('all'), first_level_back))
    s.change_state(message.from_user.id, state['al'], '0:20')
Пример #6
0
def back_to_main_menu(message: telebot.types.Message):
    s.change_state(message.from_user.id, state['st'])
    bot.send_message(message.from_user.id, main_message, parse_mode='markdown', reply_markup=get_markup(main_menu))