Пример #1
0
    def wrapped(update: Update, context: CallbackContext):
        database = context.bot_data["database"]

        try:
            func(update, context)
        except Unauthorized:
            user_id, _ = get_user_src_message(update, context)
            full_name = database.get_user_full_name(user_id)
            text = Message.BLOCKED_BY_USER.format(USER_ID=user_id, FULL_NAME=full_name)
            msg = update.effective_message.reply_html(text)
            database.add_user_message(1, user_id, msg.message_id)

        context.bot_data["lastUserId"] = Literal.ADMINS_GROUP_ID
Пример #2
0
def forward_to_user(update: Update, context: CallbackContext):
    """Send the message from admins to the user."""
    if not update.message.reply_to_message:
        return
    user_id, reply_to = get_user_src_message(update, context)

    if not (_is_legit_reply(update, context) and user_id):
        return

    context.bot.send_chat_action(chat_id=user_id, action=ChatAction.TYPING)
    context.job_queue.run_once(
        callback=_send_users,
        when=Literal.DELAY_SECONDS,
        context=(update, user_id, reply_to),
    )
Пример #3
0
def block_user_cl(update: Update, context: CallbackContext):
    """Block the user from contacting the admins based on command."""
    database = context.bot_data["database"]

    if context.args and context.args[0].isdigit():
        user_id = int(context.args[0])
    else:
        user_id, _ = get_user_src_message(update, context)
        if not user_id:
            update.message.reply_html(Message.INVALID_REPLY)
            return

    msg_id = block_user(user_id, context)

    full_name = database.get_user_full_name(user_id)
    text = Message.BLOCKED_USER.format(USER_ID=user_id, FULL_NAME=full_name)
    message = update.message.reply_html(text)
    database.add_admin_message(update.message.message_id, user_id, msg_id)
    database.add_user_message(1, user_id, message.message_id)
Пример #4
0
def edit_admin_message(update: Update, context: CallbackContext):
    """Edit the message of admins sent to user."""
    database = context.bot_data["database"]
    user_id = update.edited_message.from_user.id
    message_id = update.edited_message.message_id
    user_id, dest_message_id = database.get_user_dest_message_id_from_admins(
        message_id)

    if not _is_legit_reply(update, context):
        return

    if user_id:
        send_edited_message(context.bot, update.edited_message,
                            dest_message_id, user_id, False)
    else:
        user_id, reply_to = get_user_src_message(update, context)
        update.edited_message, update.message = update.message, update.edited_message
        context.job_queue.run_once(
            callback=_send_users,
            when=Literal.DELAY_SECONDS,
            context=(update, user_id, reply_to),
        )
Пример #5
0
def whois(update: Update, context: CallbackContext):
    """Get information about user replied to or given as argument."""
    database = context.bot_data["database"]

    if context.args and context.args[0].isdigit():
        user_id = int(context.args[0])
    else:
        user_id, _ = get_user_src_message(update, context)
        if not user_id:
            update.message.reply_html(Message.INVALID_REPLY)
            return

    username, full_name, blocked = database.get_user(user_id)
    membership = get_membership(user_id, context)
    text = Message.USER.format(
        FULL_NAME=full_name,
        USER_ID=user_id,
        USERNAME=username,
        MEMBERSHIP=membership,
        BLOCKED=blocked,
    )
    update.effective_message.reply_html(text)
Пример #6
0
 def wrapped(update: Update, context: CallbackContext):
     user_id, _ = get_user_src_message(update, context)
     if user_id:
         func(update, context)