def processor(bot, update): user = update.message.from_user text = update.message.text action, params = db_user.get_action(user.id) settings = utils.get_settings() db_user.update(user) # Check if it is group chat if update.message.chat.id < 0: if text.startswith('/'): log_message( update.message.reply_text(utils.get_constant('not_chat'))) return # logging logger.info('{} {} ({}:@{}): {}'.format(user.first_name, user.last_name, user.id, user.username, text)) # Constant behavior for button in settings['constant_behavior']: if utils.get_constant(button) == text: behave(settings['constant_behavior'][button], bot, update) return # Checking menu if action in settings: for button in settings[action]['keyboard']: if get_button_text(button) == text: behave(button, bot, update) else: action_manager(bot, update, action)
def get_student(bot, update): action, params = db_user.get_action(update.message.from_user.id) user = update.message.from_user text = update.message.text if action == 'get_student': if len(params) > 0: # If we have more than one param(it's probably date) then print group's schedule with that param date = params[0] log_message( update.message.reply_text( schedule.get_student(date=date, group=text))) default_menu(bot, update) else: # If we have none params, then we should save date and let user enter group date = text.split(',')[0] groups = [[KeyboardButton(utils.get_constant('back_to_menu'))]] for group in schedule.get_student_groups(date): groups.append([KeyboardButton(group['title'])]) log_message( update.message.reply_text(utils.get_constant('enter_group'), reply_markup=ReplyKeyboardMarkup( groups, one_time_keyboard=True))) db_user.set_action(user_id=user.id, action='get_student/{date}'.format(date=date)) else: # Choose date if action isn't "get_student" dates = [[KeyboardButton(utils.get_constant('back_to_menu'))]] for date in sorted(schedule.get_student_dates(), reverse=True): dates.append( [KeyboardButton(date + ', ' + schedule.get_weekday(date))]) log_message( update.message.reply_text(utils.get_constant('enter_date'), reply_markup=ReplyKeyboardMarkup( dates, one_time_keyboard=True))) db_user.set_action(user_id=user.id, action='get_student')
def sub_teacher(bot, update): user = update.message.from_user action, params = db_user.get_action(user.id) text = update.message.text if action == 'sub_teacher': if text == utils.get_constant('unsubscribe'): text = None log_message( update.message.reply_text( utils.get_constant('suc_unsubscribe'))) else: log_message( update.message.reply_text( utils.get_constant('suc_subscribe_teacher').format( teacher=text))) db_user.set_sub_teacher(user_id=user.id, name=text) default_menu(bot, update) else: teachers = [[KeyboardButton(utils.get_constant('back_to_menu'))]] for teacher in schedule.get_teacher_list(): teachers.append([KeyboardButton(teacher)]) sub = db_user.get_sub_teacher(user.id) info = utils.get_constant('not_subscribed_info') if sub is not None: info = utils.get_constant('subscribed_info_teacher').format( teacher=sub) teachers[0].append( KeyboardButton(utils.get_constant('unsubscribe'))) log_message( update.message.reply_text( 'Выберите или введите преподавателя, на которого вы хотите подписатся\n' + info, reply_markup=ReplyKeyboardMarkup(teachers, one_time_keyboard=True))) db_user.set_action(user_id=user.id, action='sub_teacher')
def sub_student(bot, update): user = update.message.from_user action, params = db_user.get_action(user.id) text = update.message.text if action == 'sub_student': if text == utils.get_constant('unsubscribe'): text = None log_message( update.message.reply_text( utils.get_constant('suc_unsubscribe'))) else: log_message( update.message.reply_text( utils.get_constant('suc_subscribe_group').format( group=text))) db_user.set_sub_student(user_id=user.id, group=text) default_menu(bot, update) else: groups = [[KeyboardButton(utils.get_constant('back_to_menu'))]] for group in schedule.get_student_list(): groups.append([KeyboardButton(group)]) sub = db_user.get_sub_student(user.id) info = utils.get_constant('not_subscribed_info') if sub is not None: info = utils.get_constant('subscribed_info_group').format( group=sub) groups[0].append(KeyboardButton(utils.get_constant('unsubscribe'))) log_message( update.message.reply_text( utils.get_constant('subscribe_group').format(info=info), reply_markup=ReplyKeyboardMarkup(groups, one_time_keyboard=True))) db_user.set_action(user_id=user.id, action='sub_student')