def __user_time_input_chg(update: Update, context: CallbackContext, validation, attr_name, error_state): """change mailing parameters with validation""" language_code = update.effective_user.language_code new_info = update.message.text user_id = update.effective_user.id chat_id = update.effective_chat.id # validate new_info. if False send error message and try again if validation(new_info): # update database database.set_user_attrs(user_id=user_id, attrs={attr_name: new_info}) # reset mailing job jobs.reset_mailing_job(context, user_id, chat_id, language_code) # get and send mailing page text, reply_markup = __get_mailing_page(user_id, language_code) cf.send_message( context=context, chat_id=chat_id, text=text, reply_markup=reply_markup, ) return consts.PARAMETERS_MAIN_STATE cf.send_message( context=context, chat_id=chat_id, text=get_text('format_error_parameters_text', language_code).text(), ) return error_state
def set_new_name_parameters(update: Update, context: CallbackContext): """update name""" user_id = update.effective_user.id new_name = update.message.text database.set_user_attrs(user_id=user_id, attrs={consts.USERNAME: new_name}) # send main parameters page return parameters(update, context)
def __update_attendance(update: Update, data, language_code): """update attendance""" user_id = update.effective_user.id new_attendance, _ = __get_button_vars(data) database.set_user_attrs(user_id=user_id, attrs={consts.ATTENDANCE: new_attendance}) # show main parameters page return __return_callback(update, language_code)
def __update_course(update: Update, data, language_code): """update courses info or change eng page""" if data == buttons.ENG_NEXT: return __chg_parameters_page(update, consts.ENG, language_code, keyboard.eng2_keyboard) elif data == buttons.ENG_PREV: return __chg_parameters_page(update, consts.ENG, language_code, keyboard.eng1_keyboard) user_id = update.effective_user.id subject, subtype = __get_button_vars(data) database.set_user_attrs(user_id=user_id, attrs={subject: subtype}) # show courses parameters page return __chg_parameters_page(update, consts.COURSES, language_code)
def __update_mailing_timetable(update: Update, context: CallbackContext, data, language_code): """changing mailing parameters""" user_id = update.effective_user.id chat_id = update.effective_chat.id # request user input if data == buttons.TZINFO: return __chg_parameters_page( update=update, page_name=consts.ENTER_TZINFO, ret_lvl=consts.PARAMETERS_TZINFO_STATE, language_code=language_code, ) elif data == buttons.MESSAGE_TIME: return __chg_parameters_page( update=update, page_name=consts.ENTER_TIME, ret_lvl=consts.PARAMETERS_TIME_STATE, language_code=language_code, ) if data in {buttons.ALLOW_MAILING, buttons.FORBID_MAILING}: attr = consts.MAILING_STATUS new_status = (consts.MAILING_ALLOWED if data == buttons.ALLOW_MAILING else consts.MAILING_FORBIDDEN) elif data in { buttons.DISABLE_MAILING_NOTIFICATIONS, buttons.ENABLE_MAILING_NOTIFICATIONS }: attr = consts.NOTIFICATION_STATUS new_status = (consts.NOTIFICATION_ENABLED if data == buttons.ENABLE_MAILING_NOTIFICATIONS else consts.NOTIFICATION_DISABLED) else: raise ValueError(f'Invalid data in mailing set: {data}') database.set_user_attrs(user_id=user_id, attrs={attr: new_status}) jobs.reset_mailing_job(context, user_id, chat_id, language_code) # update mailing page return __mailing_callback(update, language_code)
def admin_mute(args, language_code): """mute/unmute users""" if len(args) < 2: text = get_text('empty_user_id_admin_text', language_code).text() else: if args[0] != '-m' and args[0] != '-um': raise ValueError(f'Invalid flag: {args[0]}') flag = consts.MUTE if args[0] == '-m' else consts.UNMUTE target = args[1].split('=') if target[0] == '--all': text = get_text(f'{flag}_all_users_admin_text', language_code).text() database.set_attr_to_all(consts.MUTED, flag == consts.MUTE) elif target[0] == '--user': if len(target) == 2 and database.has_user(target[1]): database.set_user_attrs(user_nick=target, attrs={consts.MUTED: flag == consts.MUTE}) text = get_text(f'{flag}_user_admin_text', language_code).text() else: text = get_text('invalid_username_admin_text', language_code).text() else: text = get_text('invalid_flag_admin_text', language_code).text() return text, consts.MAIN_STATE