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')
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)
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')
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()
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)
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)