コード例 #1
0
def subject_callback(update: Update, data: list, language_code):
    """
    Callback function for subject keyboard
     - data: list
        - data[0] = 'subject'
        - data[1] = subject (name)
        - data[2] = attendance
        - data[3] = page
        - data[4] = 'button'
    """
    user_id = update.effective_user.id
    subject, attendance, page = data[1:-1]

    # get page text (attendance is redundant cause we received it as parameter in callback)
    text, _ = get_subject_info(subject=subject,
                               user_id=user_id,
                               page=page,
                               language_code=language_code,
                               request={
                                   consts.ATTENDANCE: attendance,
                               })
    # we need the try catch block here, because the python-telegram-bot lib throws a BadRequest error
    # when the page's content had not changed in the edit_message_text func
    # (also could be thrown when one button was double pressed very quickly)
    cf.edit_message(update=update,
                    text=text,
                    reply_markup=keyboard.subject_keyboard(
                        subject=subject,
                        attendance=attendance,
                        page=page,
                        language_code=language_code,
                    ))
コード例 #2
0
def __mailing_callback(update: Update, language_code):
    """show mailing menu"""
    text, reply_markup = __get_mailing_page(update.effective_user.id,
                                            language_code)
    cf.edit_message(
        update=update,
        text=text,
        reply_markup=reply_markup,
    )
    return consts.PARAMETERS_MAIN_STATE
コード例 #3
0
def admin_callback(update: Update, parsed_data, language_code):
    if parsed_data[1] == 'ls':
        text, _, reply_markup = admin_ls(parsed_data[2], language_code)
        cf.edit_message(
            update=update,
            text=text,
            reply_markup=reply_markup,
        )
    else:
        raise ValueError(f"Invalid admin callback: {parsed_data[1]}")
コード例 #4
0
def help_callback(update: Update, data: list, language_code):
    """change help page"""
    if data[1] in {consts.MAIN_PAGE, consts.ADDITIONAL_PAGE}:
        text = get_text(f'help_{data[1]}_text', language_code).text()
    else:
        raise ValueError(f'Invalid help callback: {data[0]}')
    cf.edit_message(
        update=update,
        text=text,
        reply_markup=keyboard.help_keyboard(data[1], language_code),
    )
コード例 #5
0
def __return_callback(update: Update, language_code):
    """show main parameters page"""
    user_id = update.effective_user.id
    cf.edit_message(
        update=update,
        text=get_text('main_parameters_text', language_code).text(
            cf.pretty_user_parameters(database.get_user_parameters(user_id),
                                      language_code)),
        reply_markup=keyboard.parameters_keyboard(language_code),
    )
    return consts.PARAMETERS_MAIN_STATE
コード例 #6
0
def cancel_callback(update: Update, context: CallbackContext):
    """manage cancel button"""
    data, language_code = cf.manage_callback_query(update)
    parsed_data = data.split('_')
    if parsed_data[0] == consts.CANCEL:
        cf.edit_message(
            update=update,
            text=get_text('cancel_main_text',
                          update.effective_user.language_code).text(),
        )
        return consts.MAIN_STATE
    cf.send_message(
        context=context,
        chat_id=update.effective_chat.id,
        text=get_text('wrong_callback_text', language_code).text(),
    )
コード例 #7
0
def __chg_parameters_page(update: Update,
                          page_name,
                          language_code,
                          parameters_keyboard=None,
                          ret_lvl=consts.PARAMETERS_MAIN_STATE):
    """change parameters page for specified value"""
    user_id = update.effective_user.id
    text = get_text(f'{page_name}_parameters_text', language_code)
    user_info = cf.pretty_user_parameters(
        database.get_user_parameters(user_id), language_code)
    text = text.text(user_info)
    if parameters_keyboard is None:
        parameters_keyboard = KEYBOARD_MAP.get(page_name)
    cf.edit_message(
        update=update,
        text=text,
        reply_markup=(parameters_keyboard(language_code)
                      if parameters_keyboard else None),
    )
    return ret_lvl
コード例 #8
0
def timetable_callback(update: Update, data: list, language_code):
    """handles timetable callbacks"""
    subject_names = database.get_user_subject_names(user_id=update.effective_user.id)
    attendance, week_parity, weekday = data[1:-1]

    cf.edit_message(
        update=update,
        text=get_weekday_timetable(
            weekday=weekday,
            subject_names=subject_names,
            attendance=attendance,
            week_parity=week_parity,
            language_code=language_code,
        ),
        reply_markup=keyboard.timetable_keyboard(
            weekday=weekday,
            attendance=attendance,
            week_parity=week_parity,
            language_code=language_code,
        )
    )
コード例 #9
0
def parameters_callback(update: Update, context: CallbackContext):
    """manage all callbacks in parameters"""
    data, language_code = cf.manage_callback_query(update)
    if data == buttons.EXIT_PARAMETERS:
        cf.edit_message(
            update=update,
            text=get_text('exit_parameters_text', language_code).text(),
        )
        return consts.MAIN_STATE
    elif data in buttons.MAIN_SET:
        return __main_callback(update, data, language_code)
    elif data in buttons.COURSES_SET:
        return __chg_course(update, data, language_code)
    elif buttons.is_course_update(data):
        return __update_course(update, data, language_code)
    elif data in buttons.ATTENDANCE_SET:
        return __update_attendance(update, data, language_code)
    elif data in buttons.MAILING_SET:
        return __update_mailing_timetable(update, context, data, language_code)
    else:
        raise ValueError(f'invalid callback for parameters: {data}')
コード例 #10
0
def deadline_callback(update: Update, data):
    text, reply_markup = make_deadline(update, data)
    cf.edit_message(update, text, reply_markup)
    return consts.MAIN_STATE