Пример #1
0
async def unblacklist(event):
    """Unblacklists given chat."""
    try:
        from userbot.modules.sql_helper.blacklist_sql import (
            del_blacklist,
            get_blacklist,
        )
    except IntegrityError:
        return await event.edit("**Executando em modo não SQL!**")

    chat_id = event.pattern_match.group(1)
    try:
        chat_id = str(await event.client.get_peer_id(chat_id))
    except Exception:
        pass  # this way, deleted chats can be unblacklisted

    if chat_id == "all":
        from userbot.modules.sql_helper.blacklist_sql import del_blacklist_all

        del_blacklist_all()
        return await event.edit("**Apagadas todas as listas negras!**")

    id_exists = False
    for i in get_blacklist():
        if chat_id == i.chat_id:
            id_exists = True

    if not id_exists:
        return await event.edit("**Este bate-papo não está na lista negra.**")

    del_blacklist(chat_id)
    await event.edit("**Bate-papo removido da lista negra!**")
Пример #2
0
async def unblacklist(event):
    """Unblacklists given chat."""
    try:
        from userbot.modules.sql_helper.blacklist_sql import (
            del_blacklist,
            get_blacklist,
        )
    except IntegrityError:
        return await event.edit("**Running on Non-SQL mode!**")

    chat_id = event.pattern_match.group(1)
    try:
        chat_id = str(await event.client.get_peer_id(chat_id))
    except Exception:
        pass  # this way, deleted chats can be unblacklisted

    if chat_id == "all":
        from userbot.modules.sql_helper.blacklist_sql import del_blacklist_all

        del_blacklist_all()
        return await event.edit("**Cleared all blacklists!**")

    id_exists = False
    for i in get_blacklist():
        if chat_id == i.chat_id:
            id_exists = True

    if not id_exists:
        return await event.edit("**This chat isn't blacklisted.**")

    del_blacklist(chat_id)
    await event.edit("**Un-blacklisted given chat!**")
Пример #3
0
def is_chat_allowed(event_obj):
    try:
        from userbot.modules.sql_helper.blacklist_sql import get_blacklist

        for blacklisted in get_blacklist():  # type: ignore
            if str(event_obj.chat_id) == blacklisted.chat_id:
                return False
    except Exception:
        pass

    return True
Пример #4
0
async def list_blacklist(event):
    """Lists all blacklisted chats."""
    try:
        from userbot.modules.sql_helper.blacklist_sql import get_blacklist
    except IntegrityError:
        return await event.edit("**Running on Non-SQL mode!**")

    chat_list = get_blacklist()
    if not chat_list:
        return await event.edit("**You haven't blacklisted any chats yet!**")

    msg = "**Blacklisted chats:**\n\n"

    for i in chat_list:
        try:
            chat = await event.client.get_entity(int(i.chat_id))
            chat = f"{chat.title} | `{i.chat_id}`"
        except (TypeError, ValueError):
            chat = f"__Couldn't fetch chat info__ | `{i.chat_id}`"

        msg += f"• {chat}\n"

    await event.edit(msg)
Пример #5
0
async def list_blacklist(event):
    """Lists all blacklisted chats."""
    try:
        from userbot.modules.sql_helper.blacklist_sql import get_blacklist
    except IntegrityError:
        return await event.edit("**Executando em modo não SQL!**")

    chat_list = get_blacklist()
    if not chat_list:
        return await event.edit(
            "**Você ainda não colocou nenhum bate-papo na lista negra!**")

    msg = "**Bate-papos na lista negra:**\n\n"

    for i in chat_list:
        try:
            chat = await event.client.get_entity(int(i.chat_id))
            chat = f"{chat.title} | `{i.chat_id}`"
        except (TypeError, ValueError):
            chat = f"__Não foi possível buscar informações do bate-papo__ | `{i.chat_id}`"

        msg += f"• {chat}\n"

    await event.edit(msg)
Пример #6
0
        async def wrapper(check):
            if check.edit_date and check.is_channel and not check.is_group:
                # Messages sent in channels can be edited by other users.
                # Ignore edits that take place in channels.
                return
            if not LOGSPAMMER:
                send_to = check.chat_id
            else:
                send_to = BOTLOG_CHATID

            if not trigger_on_fwd and check.fwd_from:
                return

            if groups_only and not check.is_group:
                await check.respond("`I don't think this is a group.`")
                return

            try:
                from userbot.modules.sql_helper.blacklist_sql import get_blacklist

                for blacklisted in get_blacklist():
                    if str(check.chat_id) == blacklisted.chat_id:
                        return
            except Exception:
                pass

            if check.via_bot_id and not insecure and check.out:
                return

            try:
                await func(check)

            # Thanks to @kandnub for this HACK.
            # Raise StopPropagation to Raise StopPropagation
            # This needed for AFK to working properly

            except events.StopPropagation:
                raise events.StopPropagation
            # This is a gay exception and must be passed out. So that it doesnt
            # spam chats
            except KeyboardInterrupt:
                pass
            except BaseException:

                # Check if we have to disable it.
                # If not silence the log spam on the console,
                # with a dumb except.

                if not disable_errors:
                    date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

                    text = "**USERBOT ERROR REPORT**\n"
                    text += "Nothing is logged except the fact of error and date."

                    ftext = "========== DISCLAIMER =========="
                    ftext += "\nThis file uploaded ONLY here,"
                    ftext += "\nwe logged only fact of error and date,"
                    ftext += "\nwe respect your privacy,"
                    ftext += "\nyou may not report this error if you've"
                    ftext += "\nany confidential data here, no one will see your data\n"
                    ftext += "================================\n\n"
                    ftext += "--------BEGIN USERBOT TRACEBACK LOG--------\n"
                    ftext += "\nDate: " + date
                    ftext += "\nChat ID: " + str(check.chat_id)
                    ftext += "\nSender ID: " + str(check.sender_id)
                    ftext += "\n\nEvent Trigger:\n"
                    ftext += str(check.text)
                    ftext += "\n\nTraceback info:\n"
                    ftext += str(format_exc())
                    ftext += "\n\nError text:\n"
                    ftext += str(sys.exc_info()[1])
                    ftext += "\n\n--------END USERBOT TRACEBACK LOG--------"

                    command = 'git log --pretty=format:"%an: %s" -10'

                    ftext += "\n\n\nLast 10 commits:\n"

                    process = await asyncsubshell(command,
                                                  stdout=asyncsub.PIPE,
                                                  stderr=asyncsub.PIPE)
                    stdout, stderr = await process.communicate()
                    result = str(stdout.decode().strip()) + str(
                        stderr.decode().strip())

                    ftext += result

                    with open("error.txt", "w+") as file:
                        file.write(ftext)

                    if LOGSPAMMER:
                        await check.respond(
                            "`Sorry, my userbot has crashed."
                            "\nThe error logs are stored in the userbot's log chat.`"
                        )

                        async with PasteBin(ftext) as client:
                            await client.post()
                            if client:
                                text += f"\n\nPasted to : [URL]({client.raw_link})"

                        await check.client.send_file(send_to,
                                                     "error.txt",
                                                     caption=text)
                        remove("error.txt")
            else:
                pass
Пример #7
0
        async def wrapper(check):
            if check.edit_date and check.is_channel and not check.is_group:
                # Messages sent in channels can be edited by other users.
                # Ignore edits that take place in channels.
                return

            if not trigger_on_fwd and check.fwd_from:
                return

            if groups_only and not check.is_group:
                await check.respond("`Eu não acho que isso seja um grupo.`")
                return

            try:
                from userbot.modules.sql_helper.blacklist_sql import get_blacklist

                for blacklisted in get_blacklist():
                    if str(check.chat_id) == blacklisted.chat_id:
                        return
            except Exception:
                pass

            if check.via_bot_id and not insecure and check.out:
                return

            try:
                await func(check)

            # Thanks to @kandnub for this HACK.
            # Raise StopPropagation to Raise StopPropagation
            # This needed for AFK to working properly

            except events.StopPropagation:
                raise events.StopPropagation
            # This is a gay exception and must be passed out. So that it doesnt
            # spam chats
            except KeyboardInterrupt:
                pass
            except BaseException as e:

                # Check if we have to disable error logging.
                if not disable_errors:
                    LOGS.exception(e)  # Log the error in console

                    date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

                    text = "**RELATÓRIO DE ERRO DO USERBOT**\n"
                    link = "[SUPORTE](https://t.me/Kircheiss)"
                    text += "Caso queira"
                    text += f"- encaminhe esta mensagem para {link}.\n"
                    text += "Nada será registrado, exceto o módulo do erro e a data\n"

                    ftext = "\nALERTA:\nEste arquivo foi carregado SOMENTE aqui, "
                    ftext += "registramos apenas o motivo do erro e a data, "
                    ftext += "Nós respeitamos sua privacidade, "
                    ftext += "você não deve relatar este erro caso existam "
                    ftext += "quaisquer dados confidenciais aqui, ninguém vai ver seus dados "
                    ftext += "se você escolher não fazer isso.\n\n"
                    ftext += "--------INÍCIO DO RELATÓRIO--------"
                    ftext += "\nData: " + date
                    ftext += "\nChat ID: " + str(check.chat_id)
                    ftext += "\nUser ID: " + str(check.sender_id)
                    ftext += "\n\nComando:\n"
                    ftext += str(check.text)
                    ftext += "\n\nInformações de traceback:\n"
                    ftext += str(format_exc())
                    ftext += "\n\nTexto de erro:\n"
                    ftext += str(sys.exc_info()[1])
                    ftext += "\n\n--------FIM DO RELATÓRIO--------"

                    command = 'git log --pretty=format:"%an: %s" -10'

                    ftext += "\n\n\nÚltimos 10 commits:\n"

                    process = await asyncsubshell(command,
                                                  stdout=asyncsub.PIPE,
                                                  stderr=asyncsub.PIPE)
                    stdout, stderr = await process.communicate()
                    result = str(stdout.decode().strip()) + str(
                        stderr.decode().strip())

                    ftext += result

                    with open("error.log", "w+") as file:
                        file.write(ftext)

                    if LOGSPAMMER:
                        await check.client.send_file(
                            BOTLOG_CHATID,
                            "error.log",
                            caption=text,
                        )
                    else:
                        await check.client.send_file(
                            check.chat_id,
                            "error.log",
                            caption=text,
                        )

                    remove("error.log")
            else:
                pass
Пример #8
0
        async def wrapper(check):
            if check.edit_date and check.is_channel and not check.is_group:
                # Messages sent in channels can be edited by other users.
                # Ignore edits that take place in channels.
                return

            if not trigger_on_fwd and check.fwd_from:
                return

            if groups_only and not check.is_group:
                await check.respond("`I don't think this is a group.`")
                return

            try:
                from userbot.modules.sql_helper.blacklist_sql import get_blacklist

                for blacklisted in get_blacklist():
                    if str(check.chat_id) == blacklisted.chat_id:
                        return
            except Exception:
                pass

            if check.via_bot_id and not insecure and check.out:
                return

            try:
                await func(check)

            # Thanks to @kandnub for this HACK.
            # Raise StopPropagation to Raise StopPropagation
            # This needed for AFK to working properly

            except events.StopPropagation:
                raise events.StopPropagation
            # This is a gay exception and must be passed out. So that it doesnt
            # spam chats
            except KeyboardInterrupt:
                pass
            except BaseException as e:

                # Check if we have to disable error logging.
                if not disable_errors:
                    LOGS.exception(e)  # Log the error in console

                    date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

                    text = "**USERBOT ERROR REPORT**\n"
                    link = "[Support Chat](https://t.me/KensurOT)"
                    text += "If you want to, you can report it"
                    text += f"- just forward this message to {link}.\n"
                    text += "I won't log anything except the fact of error and date\n"

                    ftext = "\nDisclaimer:\nThis file uploaded ONLY here, "
                    ftext += "we logged only fact of error and date, "
                    ftext += "we respect your privacy, "
                    ftext += "you may not report this error if you've "
                    ftext += "any confidential data here, no one will see your data "
                    ftext += "if you choose not to do so.\n\n"
                    ftext += "--------BEGIN USERBOT TRACEBACK LOG--------"
                    ftext += "\nDate: " + date
                    ftext += "\nChat ID: " + str(check.chat_id)
                    ftext += "\nSender ID: " + str(check.sender_id)
                    ftext += "\n\nEvent Trigger:\n"
                    ftext += str(check.text)
                    ftext += "\n\nTraceback info:\n"
                    ftext += str(format_exc())
                    ftext += "\n\nError text:\n"
                    ftext += str(sys.exc_info()[1])
                    ftext += "\n\n--------END USERBOT TRACEBACK LOG--------"

                    command = 'git log --pretty=format:"%an: %s" -10'

                    ftext += "\n\n\nLast 10 commits:\n"

                    process = await asyncsubshell(
                        command, stdout=asyncsub.PIPE, stderr=asyncsub.PIPE
                    )
                    stdout, stderr = await process.communicate()
                    result = str(stdout.decode().strip()) + str(stderr.decode().strip())

                    ftext += result

                    with open("error.log", "w+") as file:
                        file.write(ftext)

                    if LOGSPAMMER:
                        await check.client.send_file(
                            BOTLOG_CHATID,
                            "error.log",
                            caption=text,
                        )
                    else:
                        await check.client.send_file(
                            check.chat_id,
                            "error.log",
                            caption=text,
                        )

                    remove("error.log")
            else:
                pass
Пример #9
0
        async def wrapper(check):
            if check.edit_date and check.is_channel and not check.is_group:
                # Messages sent in channels can be edited by other users.
                # Ignore edits that take place in channels.
                return
            if not LOGSPAMMER:
                send_to = check.chat_id
            else:
                send_to = BOTLOG_CHATID

            if not trigger_on_fwd and check.fwd_from:
                return

            if groups_only and not check.is_group:
                await check.respond("`I don't think this is a group.`")
                return

            try:
                from userbot.modules.sql_helper.blacklist_sql import get_blacklist

                for blacklisted in get_blacklist():
                    if str(check.chat_id) == blacklisted.chat_id:
                        return
            except Exception:
                pass

            if check.via_bot_id and not insecure and check.out:
                return

            try:
                await func(check)

            # Thanks to @kandnub for this HACK.
            # Raise StopPropagation to Raise StopPropagation
            # This needed for AFK to working properly

            except events.StopPropagation:
                raise events.StopPropagation
            # This is a gay exception and must be passed out. So that it doesnt
            # spam chats
            except KeyboardInterrupt:
                pass
            except BaseException:

                # Check if we have to disable it.
                # If not silence the log spam on the console,
                # with a dumb except.

                if not disable_errors:
                    date = strftime("%Y-%m-%d %H:%M:%S", gmtime())

                    text = "**KING USERBOT ERROR REPORT**\n"
                    text += (
                        "Tidak ada yang dicatat kecuali fakta kesalahan dan tanggal\n\n"
                    )

                    ftext = "========== DISCLAIMER =========="
                    ftext += "\nFile ini HANYA diunggah di sini,"
                    ftext += "\nkami hanya mencatat fakta kesalahan dan tanggal,"
                    ftext += "\nkami menghormati privasi Anda,"
                    ftext += "\nAnda tidak boleh melaporkan kesalahan ini jika kamu sudah login group support"
                    ftext += "\ndata rahasia apa pun di sini, tidak ada yang mau lihat datamu\n"
                    ftext += "================================\n\n"
                    ftext += "--------BEGIN USERBOT TRACEBACK LOG--------\n"
                    ftext += "\nTanggal : " + date
                    ftext += "\nObrolan ID : " + str(check.chat_id)
                    ftext += "\nPengirim ID : " + str(check.sender_id)
                    ftext += "\n\nPemicu Acara :\n"
                    ftext += str(check.text)
                    ftext += "\n\nMelacak kembali info :\n"
                    ftext += str(format_exc())
                    ftext += "\n\nError text :\n"
                    ftext += str(sys.exc_info()[1])
                    ftext += "\n\n--------END USERBOT TRACEBACK LOG--------"

                    command = 'git log --pretty=format:"%an: %s" -10'

                    ftext += "\n\n\nLast 10 commits:\n"

                    process = await asyncsubshell(command,
                                                  stdout=asyncsub.PIPE,
                                                  stderr=asyncsub.PIPE)
                    stdout, stderr = await process.communicate()
                    result = str(stdout.decode().strip()) + \
                        str(stderr.decode().strip())

                    ftext += result

                    with open("error.txt", "w+") as file:
                        file.write(ftext)

                    if LOGSPAMMER:
                        await check.respond(
                            "`Maaf , bot pengguna saya crashed.\
                        \nLog kesalahan disimpan di userbot obrolan log.`")

                        log = codecs.open("error.txt", "r", encoding="utf-8")
                        data = log.read()
                        key = (requests.post(
                            "https://nekobin.com/api/documents",
                            json={
                                "content": data
                            },
                        ).json().get("result").get("key"))
                        url = f"https://nekobin.com/raw/{key}"
                        anu = f"{text}Pasted to: [Nekobin]({url})"

                        await check.client.send_file(send_to,
                                                     "error.txt",
                                                     caption=anu)
                        remove("error.txt")
            else:
                pass