def make_deadline(update: Update, day: str): language_code = update.effective_user.language_code user_id = update.effective_user.id utcoffset = timedelta( hours=int(db.get_user_attr(consts.UTCOFFSET, user_id=user_id))) deadlines = get_deadlines(day, utcoffset, language_code) return deadlines, keyboard.deadlines(utcoffset, language_code)
def send_notification(context: CallbackContext, text, language_code, user_nick=None, chat_id=None, disable_notification=False): """Send notification to specified user""" chat_id = database.get_user_attr( consts.CHAT_ID, user_nick=user_nick) if chat_id is None else chat_id send_message( context=context, chat_id=chat_id, text=get_text('notification_admin_text', language_code).text({consts.TEXT: text}), disable_notification=disable_notification, )
def report(update: Update, context: CallbackContext): """will wait for message to report if unmuted""" language_code = update.effective_user.language_code if database.get_user_attr(consts.MUTED, update.effective_user.id): text = get_text('cannot_send_report_text', language_code).text() ret_lvl = consts.MAIN_STATE reply_markup = None else: text = get_text('report_text', language_code).text() ret_lvl = consts.REPORT_MESSAGE_STATE reply_markup = keyboard.cancel_operation( consts.REPORT_STATE)(language_code) cf.send_message( context=context, chat_id=update.effective_chat.id, text=text, reply_markup=reply_markup, ) return ret_lvl
def admin(update: Update, context: CallbackContext): """ admin's control panel current functions: '/admin [-ls]' - list of all users '/admin [-n <--user=user_nick | --all> [--s=<0 | 1>] ]' - send a notification to the specified user or to all users. Flag --s (silence) is set to 0 by default '/admin [-m |-um <--user=user_nick | --all>]' - mute/unmute reports from user """ language_code = update.effective_user.language_code args = context.args ret_lvl = consts.MAIN_STATE reply_markup = None # unauthorized user tries to access admin panel if not database.get_user_attr('admin', user_id=update.effective_user.id): text = get_text('unauthorized_user_admin_text', language_code).text() # empty args elif len(args) == 0: text = get_text('no_args_admin_text', language_code).text() # notifications elif args[0] == '-n': text, ret_lvl, reply_markup = admin_request_notify(context, args, language_code) # list of the users elif args[0] == '-ls': text, ret_lvl, reply_markup = admin_ls(0, language_code) # mute/unmute users elif args[0] == '-m' or args[0] == '-um': text, ret_lvl = admin_mute(args, language_code) else: text = get_text('invalid_flag_admin_text', language_code).text() cf.send_message( context=context, chat_id=update.effective_chat.id, text=text, reply_markup=reply_markup, ) return ret_lvl
def doc(update: Update, context: CallbackContext): """ show documentation if argument specified, shows docs for command shows special docs for admins """ language_code = update.effective_user.language_code args = context.args if_admin = database.get_user_attr('admin', user_id=update.effective_user.id) if len(args) > 2: text = get_text('quantity_error_doc_text', language_code).text() else: if len(args) == 0: text = get_text('doc_text', language_code).text({ 'command': consts.ALL, 'admin': if_admin }) else: if args[0] not in consts.DOC_COMMANDS: text = get_text('wrong_command_error_doc_text', language_code).text() else: text = get_text('doc_text', language_code).text({ 'command': args[0], 'admin': if_admin }) if not if_admin and args[0] == 'admin': text += get_text('doc_unavailable_text', language_code).text() cf.send_message( context=context, chat_id=update.effective_chat.id, text=text, )
def mailing_allowed(user_id): """checks user's mailing status""" return db.get_user_attr(consts.MAILING_STATUS, user_id=user_id) == consts.MAILING_ALLOWED