コード例 #1
0
ファイル: bans.py プロジェクト: kxrumi/MeguRobot
def unban(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Dudo que sea un usuario.")
        return log_message

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "Usuario no encontrado":
            message.reply_text("Parece que no puedo encontrar a este usuario.")
            return log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text(
            "Cómo me desharía del ban? sino no estuviera aquí...")
        return log_message

    if is_user_in_chat(chat, user_id):
        message.reply_text("No está esa persona ya aquí?")
        return log_message

    chat.unban_member(user_id)
    message.reply_text("Ok, este usuario puede unirse!")

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#UnBan\n"
        f"<b>Administrador:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>Usuario:</b> {mention_html(member.user.id, member.user.first_name)}"
    )
    if reason:
        log += f"\n<b>Razón:</b> {reason}"

    return log
コード例 #2
0
ファイル: bans.py プロジェクト: kxrumi/MeguRobot
def selfunban(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    bot, args = context.bot, context.args
    if user.id not in SUDO_USERS or user.id not in FROG_USERS:
        return

    try:
        chat_id = int(args[0])
    except:
        message.reply_text("Dame un ID de chat válido.")
        return

    chat = bot.getChat(chat_id)

    try:
        member = chat.get_member(user.id)
    except BadRequest as excp:
        if excp.message == "Usuario no encontrado":
            message.reply_text("Parece que no puedo encontrar a este usuario.")
            return
        else:
            raise

    if is_user_in_chat(chat, user.id):
        message.reply_text("No está ya en el chat?")
        return

    chat.unban_member(user.id)
    message.reply_text("Listo, lo he desbaneado.")

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#UnBan\n"
        f"<b>Usuario:</b> {mention_html(member.user.id, member.user.first_name)}"
    )

    return log
コード例 #3
0
ファイル: remote_cmds.py プロジェクト: kxrumi/MeguRobot
def runmute(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message

    if not args:
        message.reply_text("Parece que no te refieres a un grupo/suario.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            "No parece que se refiera a un usuario o el ID especificado es incorrecto."
        )
        return
    elif not chat_id:
        message.reply_text("Parece que no te refieres a un grupo.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat no encontrado! Asegúrese de haber ingresado una ID de chat válida y yo sea parte de ese chat."
            )
            return
        else:
            raise

    if chat.type == "private":
        message.reply_text("Lo siento, pero es un chat privado!")
        return

    if (not is_bot_admin(chat, bot.id)
            or not chat.get_member(bot.id).can_restrict_members):
        message.reply_text(
            "No puedo dejar de restringir a la gente! Asegúrate de que sea administradora y pueda desbloquear usuarios."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "Usuario no encontrado":
            message.reply_text("Parece que no puedo encontrar a este usuario")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        if (member.can_send_messages and member.can_send_media_messages
                and member.can_send_other_messages
                and member.can_add_web_page_previews):
            message.reply_text(
                "Este usuario ya tiene derecho a hablar en ese chat.")
            return

    if user_id == bot.id:
        message.reply_text("No voy a DESMUTARME, soy un administradora allí!")
        return

    try:
        bot.restrict_chat_member(
            chat.id,
            int(user_id),
            permissions=ChatPermissions(
                can_send_messages=True,
                can_send_media_messages=True,
                can_send_other_messages=True,
                can_add_web_page_previews=True,
            ),
        )
        message.reply_text("Ok, este usuario puede hablar en ese chat!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("Desmuteado!", quote=False)
        elif excp.message in RUNMUTE_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unmnuting user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text(
                "Bueno maldita sea, no puedo silenciar a ese usuario.")
コード例 #4
0
ファイル: remote_cmds.py プロジェクト: kxrumi/MeguRobot
def runban(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message

    if not args:
        message.reply_text("Parece que no te refieres a un grupo/usuario.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            "No parece que se refiera a un usuario o el ID especificado es incorrecto."
        )
        return
    elif not chat_id:
        message.reply_text("Parece que no te refieres a un chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat no encontrado! Asegúrese de haber ingresado una ID de chat válida y yo sea parte de ese chat."
            )
            return
        else:
            raise

    if chat.type == "private":
        message.reply_text("Lo siento, pero es un chat privado!")
        return

    if (not is_bot_admin(chat, bot.id)
            or not chat.get_member(bot.id).can_restrict_members):
        message.reply_text(
            "¡No puedo dejar de restringir a la gente! Asegúrate de que soy administrador y puedo desbloquear usuarios."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "Usuario no encontrado":
            message.reply_text(
                "Parece que no puedo encontrar a este usuario there")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Por qué intentas desbanear de forma remota a alguien que ya está en ese chat?"
        )
        return

    if user_id == bot.id:
        message.reply_text("No voy a DESBANEARME, soy administradora allí!")
        return

    try:
        chat.unban_member(user_id)
        message.reply_text("Ok, este usuario puede unirse a ese chat!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text("Desbaneado!", quote=False)
        elif excp.message in RUNBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unbanning user %s in chat %s (%s) due to %s",
                user_id,
                chat.title,
                chat.id,
                excp.message,
            )
            message.reply_text("Well damn, I can't unban that user.")