Beispiel #1
0
def show_schedule(message):
    group = orm.get_user_by_id(message.from_user.id).group_name
    cmd = extract_command(message.text)

    methods_map = {
        'today': api.today_schedule,
        'tomorrow': api.tomorrow_schedule,
        'week': api.week_schedule,
        'nextweek': api.next_week_schedule,
    }

    no_lessons_map = {
        'today': msgs.NO_LESSONS_TODAY,
        'tomorrow': msgs.NO_LESSONS_TOMORROW,
        'week': msgs.NO_LESSONS_WEEK,
        'nextweek': msgs.NO_LESSONS_NEXT_WEEK,
    }

    resp = methods_map[cmd](group)

    if (resp['error'] != 'Not Found') and (resp['error'] is not None):
        msg = msgs.API_SERVER_ERROR
    elif resp['response'] is None:
        msg = no_lessons_map[cmd]
    else:
        msg = schedule_to_markdown(resp['response']['schedule'])

    bot.send_message(message.chat.id, msg, parse_mode='Markdown')
Beispiel #2
0
def get_current_group(message):
    user = orm.get_user_by_id(message.from_user.id)

    if user.group_name == None:
        msg = msgs.SELECT_GROUP
    else:
        msg = msgs.SELECTED_GROUP.\
            format(user.group_name)

    bot.send_message(message.chat.id, msg)
Beispiel #3
0
def show_lecturers(message):
    group = orm.get_user_by_id(message.from_user.id).group_name
    subjects = api.subject_lecturers(group)

    if subjects:
        msg = subject_lecturers_to_markdown(subjects)
    else:
        msg = msgs.NO_SCHEDULE

    bot.send_message(message.chat.id, msg, parse_mode='Markdown')
Beispiel #4
0
def gr(message):
    args = extract_arg(message.text)
    user = orm.get_user_by_id(message.from_user.id)
    group_name = args[0]

    # send suggestions if recived group name is not exist
    if not api.is_exist_group(group_name):
        bot.send_message(message.chat.id, msgs.WRONG_GROUP)
        sugg_groups = api.get_group_suggestions(group_name)
        # make string with up to 8 suggested groups
        if sugg_groups:
            sugg_string = '\n• '.join(sugg_groups[:8])
            bot.send_message(message.chat.id,
                             msgs.SUGGEST_GROUP.format(sugg_string))
        return

    if user.group_name == group_name:
        bot.send_message(message.chat.id, msgs.SAME_GROUP.format(group_name))
        return

    bot.send_message(message.chat.id, msgs.CHANGE_GROUP.format(group_name))

    user.group_name = group_name
    orm.session.commit()
Beispiel #5
0
 def inner(message):
     user = orm.get_user_by_id(message.from_user.id)
     if not user:
         orm.create_user(message.from_user.id, None)
     return handler(message)
Beispiel #6
0
 def inner(message):
     user = orm.get_user_by_id(message.from_user.id)
     if (not user) or (user.group_name is None):
         bot.send_message(message.chat.id, msgs.SELECT_GROUP)
         return
     return handler(message)