async def filters_active(event):
    """ For .filters command, lists all of the active filters in a chat. """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit("`Database connections failing!`")
        return
    transact = "`There are no filters in this chat.`"
    filters = await get_filters(event.chat_id)
    for filt in filters:
        if transact == "`There are no filters in this chat.`":
            transact = "Active filters in this chat:\n"
            transact += " • **{}** - `{}`\n".format(filt["keyword"],
                                                    filt["msg"])
        else:
            transact += " • **{}** - `{}`\n".format(filt["keyword"],
                                                    filt["msg"])

    await event.edit(transact)
Exemple #2
0
async def lists_active(event):
    """ For .lists command, list all of the lists saved in a chat. """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit(DB_FAILED)
        return

    message = NO_LISTS
    lists = await get_lists(event.chat_id)
    if lists.count() != 0:
        message = "Lists saved in this chat:\n"

        for _list in lists:
            message += "🔹 **{} ({})**\n".format(
                _list["name"], "Local" if
                (_list["chat_id"] != 0) else "Global")

    await event.edit(message)
Exemple #3
0
async def gspider(gspdr):
    """ For .gmute command, gmutes the target in the userbot """
    cmd = gspdr.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        # Admin or creator check
        chat = await gspdr.get_chat()
        admin = chat.admin_rights
        creator = chat.creator

        # If not admin and not creator, return
        if not admin and not creator:
            await gspdr.edit(NO_ADMIN)
            return

        # Check if the function running under SQL mode
        if not is_mongo_alive() or not is_redis_alive():
            await gspdr.edit(NO_SQL)
            return
        user = await get_user_from_event(gspdr)
        if user:
            pass
        else:
            return

        # If the targeted user is a SUDO
        if user.id in BRAIN_CHECKER:
            await gspdr.edit(
                "`Errore Mute Globale! Non posso mutare globalmente questo utente.`"
            )
            return

        # If pass, inform and start gmuting
        await gspdr.edit("`Prendi un enorme nastro, e mutalo dappertutto!`")

        if await gmute(user.id) is False:
            await gspdr.edit(
                '`Errore! Utente probabilmente già globalmente mutato.`')
        else:
            await gspdr.edit("`Mutato globalmente!`")

            if BOTLOG:
                await gspdr.client.send_message(
                    BOTLOG_CHATID, "#GMUTE\n"
                    f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                    f"CHAT: {gspdr.chat.title}(`{gspdr.chat_id}`)")
Exemple #4
0
async def unmoot(unmot):
    """ For .unmute command, unmute the target """
    if not unmot.text[0].isalpha() and unmot.text[0] \
            not in ("/", "#", "@", "!"):

        # Admin or creator check
        chat = await unmot.get_chat()
        admin = chat.admin_rights
        creator = chat.creator

        # If not admin and not creator, return
        if not admin and not creator:
            await unmot.edit(NO_ADMIN)
            return

        # Check if the function running under SQL mode
        if not is_mongo_alive() or not is_redis_alive():
            await unmot.edit(NO_SQL)
            return
        # If admin or creator, inform the user and start unmuting
        await unmot.edit('```Unmutando...```')
        user = await get_user_from_event(unmot)
        if user:
            pass
        else:
            return

        if await unmute(unmot.chat_id, user.id) is False:
            return await unmot.edit(
                "`Errore! Utente probabilmente già mutato.`")
        else:

            try:
                await unmot.client(
                    EditBannedRequest(unmot.chat_id, user.id, UNMUTE_RIGHTS))
                await unmot.edit("```Unmutato con successo!```")
            except UserIdInvalidError:
                await unmot.edit("`Uh oh my unmute logic broke!`")
                return

            if BOTLOG:
                await unmot.client.send_message(
                    BOTLOG_CHATID, "#UNMUTE\n"
                    f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                    f"CHAT: {unmot.chat.title}(`{unmot.chat_id}`)")
Exemple #5
0
async def auto_accept(event):
    """ Will approve automatically if you texted them first. """
    if event.is_private and not (await event.get_sender()).bot:
        if not is_mongo_alive() or not is_redis_alive():
            return
        chat = await event.get_chat()
        if isinstance(chat, User):
            if is_approved(event.chat_id):
                return
            async for message in event.client.iter_messages(chat.id, reverse=True, limit=1):
                if message.from_id == (await event.client.get_me()).id:
                    approve(chat.id)
                if BOTLOG:
                    await event.client.send_message(
                        BOTLOG_CHATID,
                        "#AUTO-APPROVED\n"
                        + "User: "******"[{chat.first_name}](tg://user?id={chat.id})",
                    )
Exemple #6
0
async def notes_active(event):
    """ For .saved command, list all of the notes saved in a chat. """
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit("`Database connections failing!`")
            return

        message = "`There are no saved notes in this chat`"
        notes = await get_notes(event.chat_id)
        for note in notes:
            if message == "`There are no saved notes in this chat`":
                message = "Notes saved in this chat:\n"
                message += "🔹 **{}**\n".format(note["name"])
            else:
                message += "🔹 **{}**\n".format(note["name"])

        await event.edit(message)
Exemple #7
0
async def gspider(gspdr):
    """ For .gmute command, gmutes the target in the userbot """
    cmd = gspdr.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        # Admin or creator check
        chat = await gspdr.get_chat()
        admin = chat.admin_rights
        creator = chat.creator

        # If not admin and not creator, return
        if not admin and not creator:
            await gspdr.edit(NO_ADMIN)
            return

        # Check if the function running under SQL mode
        if not is_mongo_alive() or not is_redis_alive():
            await gspdr.edit(NO_SQL)
            return
        user = await get_user_from_event(gspdr)
        if user:
            pass
        else:
            return

        # If the targeted user is a SUDO
        if user.id in BRAIN_CHECKER:
            await gspdr.edit("`Gmute Error! Couldn't gmute this user`")
            return

        # If pass, inform and start gmuting
        await gspdr.edit("`Grabs a huge, sticky duct tape!`")

        if await gmute(user.id) is False:
            await gspdr.edit('`Error! User probably already gmuted.`')
        else:
            await gspdr.edit("`Globally taped!`")

            if BOTLOG:
                await gspdr.client.send_message(
                    BOTLOG_CHATID,
                    "#GMUTE\n"
                    f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                    f"CHAT: {gspdr.chat.title}(`{gspdr.chat_id}`)"
                )
Exemple #8
0
async def setliststate(event):
    """ For .setlist command, changes the state of a list. """
    if environ.get("isSuspended") == "True":
        return
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit(DB_FAILED)
        return

    _futureState = event.pattern_match.group(2)
    changeToGlobal = None

    if _futureState == "global":
        changeToGlobal = True
    elif _futureState == "local":
        changeToGlobal = False

    textx = await event.get_reply_message()
    listname = None

    if textx:
        x = re.search(r"\[Paperplane-List] List \*\*(\w*)", textx.text)
        listname = x.group(1)
    elif event.pattern_match.group(1):
        listname = event.pattern_match.group(1)
    else:
        await event.edit(f"`Pass a list to remove!` {CHK_HELP}")
        return

    _list = await get_list(event.chat_id, listname)

    chatid = 0 if changeToGlobal else event.chat_id

    msg = f"`The state of list {listname} changed to \
{_futureState} successfully.`"

    if await set_list(_list['chat_id'], listname, chatid) is True:
        await event.edit(msg)
    else:
        await event.edit(f"`List {listname} not found!`")

    if BOTLOG:
        await event.client.send_message(
            BOTLOG_CHATID,
            f"Changed state of list {listname} to {_futureState}")
async def add_new_filter(event):
    """ Command for adding a new filter """
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit("`Database connections failing!`")
            return
        message = event.text
        keyword = message.split()
        string = ""
        for i in range(2, len(keyword)):
            string = string + " " + str(keyword[i])

        msg = "`Filter` **{}** `{} successfully`"

        if await add_filter(event.chat_id, keyword[1], string[1:]) is True:
            await event.edit(msg.format(keyword[1], 'added'))
        else:
            await event.edit(msg.format(keyword[1], 'updated'))
Exemple #10
0
async def lists_active(event):
    """ For .lists command, list all of the lists saved in a chat. """
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit("`Database connections failing!`")
            return

        message = "`There are no saved lists in this chat`"
        lists = await get_lists(event.chat_id)
        if lists.count() != 0:
            message = "Lists saved in this chat:\n"

            for _list in lists:
                message += "🔹 **{} ({})**\n".format(
                    _list["name"], "Local" if
                    (_list["chat_id"] != 0) else "Global")

        await event.edit(message)
Exemple #11
0
async def filter_incoming_handler(handler):
    """Checks if the incoming message contains handler of a filter"""
    try:
        if not (await handler.get_sender()).bot:
            if not is_mongo_alive() or not is_redis_alive():
                await handler.edit("`Database connections failing!`")
                return

            filters = await get_filters(handler.chat_id)
            if not filters:
                return
            for trigger in filters:
                pattern = (r"( |^|[^\w])" + re.escape(trigger["keyword"]) +
                           r"( |$|[^\w])")
                if re.search(pattern, handler.text, flags=re.IGNORECASE):
                    await handler.reply(trigger["msg"])
                    return
    except AttributeError:
        pass
Exemple #12
0
async def add_filter(event):
    """ For .save command, saves notes in a chat. """
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit("`Database connections failing!`")
            return

        notename = event.pattern_match.group(1)
        string = event.text.partition(notename)[2]
        if event.reply_to_msg_id:
            string = " " + (await event.get_reply_message()).text

        msg = "`Note {} successfully. Use` #{} `to get it`"

        if await add_note(event.chat_id, notename, string[1:]) is False:
            return await event.edit(msg.format('updated', notename))
        else:
            return await event.edit(msg.format('added', notename))
Exemple #13
0
async def unmoot(unmot):
    """ For .unmute command, unmute the target """
    # Admin or creator check
    chat = await unmot.get_chat()
    admin = chat.admin_rights
    creator = chat.creator

    # If not admin and not creator, return
    if not admin and not creator:
        await unmot.edit(NO_ADMIN)
        return

    # Check if the function running under SQL mode
    if not is_mongo_alive() or not is_redis_alive():
        await unmot.edit(NO_SQL)
        return
    # If admin or creator, inform the user and start unmuting
    await unmot.edit('```Unmuting...```')
    user = await get_user_from_event(unmot)
    # Do we need a reason to unmute ?
    user = user[0]
    if user:
        pass
    else:
        return

    if await unmute(unmot.chat_id, user.id) is False:
        return await unmot.edit("`Error! User probably already unmuted.`")
    else:

        try:
            await unmot.client(
                EditBannedRequest(unmot.chat_id, user.id, UNMUTE_RIGHTS))
            await unmot.edit("```Unmuted Successfully```")
        except UserIdInvalidError:
            await unmot.edit("`Uh oh my unmute logic broke!`")
            return

        if BOTLOG:
            await unmot.client.send_message(
                BOTLOG_CHATID, "#UNMUTE\n"
                f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                f"CHAT: {unmot.chat.title}(`{unmot.chat_id}`)")
Exemple #14
0
async def unmoot(unmot):
    """For .unmute command, unmute the target"""
    # Admin or creator check
    chat = await unmot.get_chat()
    admin = chat.admin_rights
    creator = chat.creator

    # If not admin and not creator, return
    if not admin and not creator:
        await unmot.edit(NO_ADMIN)
        return

    # Check if the function running under SQL mode
    if not is_mongo_alive() or not is_redis_alive():
        await unmot.edit(NO_SQL)
        return
    # If admin or creator, inform the user and start unmuting
    await unmot.edit("```Unmuting...```")
    user = await helpers.get_user_from_event(unmot)
    if not user:
        await unmoot.edit(
            "`Missing user to unmute! Either reply to message, mention the user or specify a valid ID!`"
        )

    if await unmute(unmot.chat_id, user.id) is False:
        return await unmot.edit("`Error! User is probably already unmuted.`")

    try:
        await unmot.client(
            EditBannedRequest(unmot.chat_id, user.id, UNMUTE_RIGHTS))
        await unmot.edit("```Unmuted!```")
    except UserIdInvalidError:
        await unmot.edit("`Uh oh, my unmute logic broke!`")
        return

    if BOTLOG:
        await unmot.client.send_message(
            BOTLOG_CHATID,
            "#UNMUTE\n"
            f"USER: [{user.first_name}](tg://user?id={user.id})\n"
            f"CHAT: {unmot.chat.title}(`{unmot.chat_id}`)",
        )
Exemple #15
0
async def ungmoot(un_gmute):
    """ For .ungmute command, ungmutes the target in the userbot """
    if not un_gmute.text[0].isalpha() and un_gmute.text[0] \
            not in ("/", "#", "@", "!"):
        # Admin or creator check
        chat = await un_gmute.get_chat()
        admin = chat.admin_rights
        creator = chat.creator

        # If not admin and not creator, return
        if not admin and not creator:
            await un_gmute.edit(NO_ADMIN)
            return

        # Check if the function running under SQL mode
        if not is_mongo_alive() or not is_redis_alive():
            await un_gmute.edit(NO_SQL)
            return

        user = await get_user_from_event(un_gmute)
        if user:
            pass
        else:
            return

        # If pass, inform and start ungmuting
        await un_gmute.edit('```Ungmuting...```')

        if await ungmute(user.id) is False:
            await un_gmute.edit("`Error! User probably not gmuted.`")
        else:

            # Inform about success
            await un_gmute.edit("```Ungmuted Successfully```")

            if BOTLOG:
                await un_gmute.client.send_message(
                    BOTLOG_CHATID,
                    "#UNGMUTE\n"
                    f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                    f"CHAT: {un_gmute.chat.title}(`{un_gmute.chat_id}`)"
                )
Exemple #16
0
async def filter_incoming_handler(handler):
    """ Checks if the incoming message contains handler of a filter """
    try:
        if not (await handler.get_sender()).bot:
            if not is_mongo_alive() or not is_redis_alive():
                await handler.edit("`Database connections failing!`")
                return
            incoming_message = handler.text
            filters = await get_filters(handler.chat_id)
            if not filters:
                return
            for trigger in filters:
                pro = re.fullmatch(trigger["keyword"],
                                   incoming_message,
                                   flags=re.IGNORECASE)
                if pro:
                    await handler.reply(trigger["msg"])
                    return
    except AttributeError:
        pass
Exemple #17
0
async def add_new_filter(event):
    """ Command for adding a new filter """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit("`Database connections failing!`")
        return
    message = event.text
    keyword = message.split()
    string = ""
    for i in range(2, len(keyword)):
        string = string + " " + str(keyword[i])

    if event.reply_to_msg_id:
        string = " " + (await event.get_reply_message()).text

    msg = "`Filter` **{}** `{} successfully`"

    if await add_filter(event.chat_id, keyword[1], string[1:]) is True:
        await event.edit(msg.format(keyword[1], 'added'))
    else:
        await event.edit(msg.format(keyword[1], 'updated'))
Exemple #18
0
async def add_filter(event):
    """ For .save command, saves notes in a chat. """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit("`Database connections failing!`")
        return

    notename = event.pattern_match.group(1)
    string = event.pattern_match.group(2)

    if event.reply_to_msg_id:
        string = (await event.get_reply_message()).text

    msg = "`{} note #{}`"

    if await add_note(event.chat_id, notename, string) is False:
        message = msg.format('Updated', notename)
        return await event.edit(message, delete_in=3)
    else:
        message = msg.format('Added', notename)
        return await event.edit(message, delete_in=3)
Exemple #19
0
async def edit_list_item(event):
    """ For .editlistitem command, edit an individual item on a list. """
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit(DB_FAILED)
            return

        textx = await event.get_reply_message()
        listname = None

        if textx:
            x = re.search(r"\[Paperplane-List] List \*\*(\w*)", textx.text)
            listname = x.group(1)
        elif event.pattern_match.group(1):
            listname = event.pattern_match.group(1)
        else:
            await event.edit(f"`Pass a list!` {CHK_HELP}")
            return

        item_number = int(event.pattern_match.group(2))

        _list = await get_list(event.chat_id, listname)
        content = _list['items']
        content[item_number - 1] = event.pattern_match.group(3)

        msg = f"`Item {item_number} edited successfully.\n"
        msg += f"Use` ${listname} `to get the list.`"

        if await add_list(event.chat_id, listname, content) is False:
            await event.edit(msg)
        else:
            await event.edit(LIST_NOT_FOUND.format(listname))

        if BOTLOG:
            listat = "global storage" if _list['chat_id'] else str(
                event.chat_id)

            log = "Edited item {item_number} of "
            log += f"{listname} in {listat} successfully."
            await event.client.send_message(BOTLOG_CHATID, log)
Exemple #20
0
async def removelists(event):
    """ For .rmlist command, delete list with the given name."""
    cmd = event.text[0]
    if not cmd.isalpha() and cmd not in ("/", "#", "@", "!"):
        if not is_mongo_alive() or not is_redis_alive():
            await event.edit("`Database connections failing!`")
            return
        listname = event.pattern_match.group(1)
        _list = await get_list(event.chat_id, listname)

        if await delete_list(event.chat_id, listname) is False:
            await event.edit("`Couldn't find list:` **{}**".format(listname))
        else:
            await event.edit(
                "`Successfully deleted list:` **{}**".format(listname))

        if BOTLOG:
            listat = "global storage" if _list['chat_id'] == 0 else str(
                event.chat_id)
            await event.client.send_message(
                BOTLOG_CHATID, f"Removed list {listname} from {listat}")
Exemple #21
0
async def lists_logic(event):
    """ Lists logic. """
    try:
        if not (await event.get_sender()).bot:
            if not is_mongo_alive() or not is_redis_alive():
                return

            listname = event.text[1:]
            _list = await get_list(event.chat_id, listname)
            if _list:
                return_str = ""

                if _list['items']:
                    for i, item in enumerate(_list['items']):
                        return_str += f"{i+1}. {item}\n"
                else:
                    return_str = "`This list is empty!`"

                await event.reply(return_str)
    except BaseException:
        pass
Exemple #22
0
async def add_new_filter(event):
    """ Command for adding a new filter """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit("`Database connections failing!`")
        return
    keyword = event.pattern_match.group(1) or event.pattern_match.group(2)
    string = event.pattern_match.group(3)

    if event.reply_to_msg_id:
        string = " " + (await event.get_reply_message()).text

    msg = "`Filter` **{}** `{} successfully`"

    if BOTLOG:
        if await add_filter(event.chat_id, keyword, string) is True:
            await event.client.send_message(BOTLOG_CHATID,
                                            msg.format(keyword, 'added'))
        else:
            await event.client.send_message(BOTLOG_CHATID,
                                            msg.format(keyword, 'updated'))
    event.delete()
async def unexclude_grp(excl):
    if not is_mongo_alive():
        await excl.edit("`Database connections failing!`")
        return

    chat_id = excl.pattern_match.group(1)

    if not chat_id:
        chat_id = excl.chat_id

    await remove_exclude_group(chat_id)

    await excl.edit(
        f"`This chat (ID: {chat_id}) has been removed from Paperplane Exclude!`"
    )

    if BOTLOG:
        await excl.client.send_message(BOTLOG_CHATID, "#UNEXCLUDE\n"
                                       f"Chat ID: {chat_id}\n")

    return
Exemple #24
0
async def getlist_logic(event):
    """ For .getlist, get the list by the name. """
    if environ.get("isSuspended") == "True":
        return
    if not (await event.get_sender()).bot:
        if not is_mongo_alive() or not is_redis_alive():
            return

        textx = await event.get_reply_message()
        listname = None

        if textx:
            x = re.search(r"\[Paperplane-List] List \*\*(\w*)", textx.text)
            listname = x.group(1)
        elif event.pattern_match.group(1):
            listname = event.pattern_match.group(1)
        else:
            await event.edit(f"`Pass a list to get!` {CHK_HELP}")
            return

        _list = await get_list(event.chat_id, listname)
        if _list:
            storage = "None"
            if _list['chat_id'] == 0:
                storage = "global"
            else:
                storage = str(_list['chat_id'])

            return_str = LIST_HEADER.format(listname, storage)

            if _list['items']:
                for i, item in enumerate(_list['items']):
                    return_str += f"{i+1}. {item}\n"
            else:
                return_str = "`This list is empty!`"

            await event.edit(return_str)
        else:
            await event.edit(f"`List {listname} not found!`")
Exemple #25
0
async def muter(moot):
    """Used for deleting the messages of muted people"""
    if not is_mongo_alive() or not is_redis_alive():
        return
    muted = await get_muted(moot.chat_id)
    gmuted = await get_gmuted()
    rights = ChatBannedRights(
        until_date=None,
        send_messages=True,
        send_media=True,
        send_stickers=True,
        send_gifs=True,
        send_games=True,
        send_inline=True,
        embed_links=True,
    )
    if muted:
        for i in muted:
            if i == moot.sender_id:
                await moot.delete()
                try:
                    await moot.client(
                        EditBannedRequest(moot.chat_id, moot.sender_id,
                                          rights))

                # We couldn't hit him an API mute, probably an admin?
                # Telethon sometimes fails to grab user details properly gaurd
                # it also
                except (
                        UserAdminInvalidError,
                        ChatAdminRequiredError,
                        BadRequestError,
                        UserIdInvalidError,
                ):
                    pass
    for i in gmuted:
        if i == moot.sender_id:
            await moot.delete()
Exemple #26
0
async def addlist(event):
    """ For .add(g)list command, saves lists in a chat. """
    if not is_mongo_alive() or not is_redis_alive():
        await event.edit(DB_FAILED)
        return

    is_global = event.pattern_match.group(1) == "g"

    listname = event.pattern_match.group(2)
    content = event.text.partition(f"{listname} ")[2].splitlines()

    msg = "`List {} successfully. Use` ${} `to get it.`"

    chatid = 0 if is_global else event.chat_id

    if await add_list(chatid, listname, content) is False:
        await event.edit(msg.format('updated', listname))
    else:
        await event.edit(msg.format('created', listname))

    if BOTLOG:
        listat = "global storage" if is_global else str(event.chat_id)
        await event.client.send_message(
            BOTLOG_CHATID, f"Created list {listname} in {listat}")
async def fedban_all(msg):
    if not is_mongo_alive() or not is_redis_alive():
        await msg.edit("`Database connections failing!`")
        return

    banreason = "[paperplane] "

    user, reason = await helpers.get_user_and_reason_from_event(msg)
    if not user:
        await msg.edit(
            "`Missing user to FBan! Either reply to message, mention the user or specify a valid ID!`"
        )
        return
    banid = user.id
    banreason += reason if reason else "FBan"
    message = ""

    textx = await msg.get_reply_message()
    if not textx:
        message += "`Reply message missing! Might fail on some bots! Still attempting to FBan!`"
        await msg.edit(message)

    banlist = await get_fban()
    count = 0
    banid_list = [row["chatid"] for row in banlist]
    for bangroup in banid_list:
        async with bot.conversation(bangroup) as conv:
            await conv.send_message(f"!fban {banid} {banreason}")
            count += 1
            # Sleep to avoid a floodwait.
            # Prevents floodwait if user is a fedadmin on too many feds
            await asyncio.sleep(0.1)

    # We can't see if the user is actually FBanned.
    message = f"\n`Fbanned on {str(count)} fed(s)! Paperplane doesn't check if the FBans were successful.`"
    await msg.edit(message)
Exemple #28
0
async def spider(spdr):
    """
    This function is basically muting peeps
    """
    # Check if the function running under SQL mode
    if not is_mongo_alive() or not is_redis_alive():
        await spdr.edit(NO_SQL)
        return

    # Admin or creator check
    chat = await spdr.get_chat()
    admin = chat.admin_rights
    creator = chat.creator

    # If not admin and not creator, return
    if not admin and not creator:
        await spdr.edit(NO_ADMIN)
        return

    user = await get_user_from_event(spdr)
    if user:
        pass
    else:
        return

    self_user = await spdr.client.get_me()

    if user.id == self_user.id:
        await spdr.edit("`Mute Error! You are not supposed to mute yourself!`")
        return

    # If everything goes well, do announcing and mute
    await spdr.edit("`Gets a tape!`")
    if await mute(spdr.chat_id, user.id) is False:
        return await spdr.edit('`Error! User probably already muted.`')
    else:
        try:
            await spdr.client(
                EditBannedRequest(spdr.chat_id, user.id, MUTE_RIGHTS))
            # Announce that the function is done
            await spdr.edit("`Safely taped!`")

            # Announce to logging group
            if BOTLOG:
                await spdr.client.send_message(
                    BOTLOG_CHATID, "#MUTE\n"
                    f"USER: [{user.first_name}](tg://user?id={user.id})\n"
                    f"CHAT: {spdr.chat.title}(`{spdr.chat_id}`)")
        except UserIdInvalidError:
            return await spdr.edit("`Uh oh my unmute logic broke!`")

        # These indicate we couldn't hit him an API mute, possibly an
        # admin?

        except (UserAdminInvalidError, ChatAdminRequiredError,
                BadRequestError):
            return await spdr.edit("""`I couldn't mute on the API,
            could be an admin possibly?
            Anyways muted on the userbot.
            I'll automatically delete messages
            in this chat from this person`""")
Exemple #29
0
async def permitpm(event):
    """ Permits people from PMing you without approval. \
        Will block retarded nibbas automatically. """
    if PM_AUTO_BAN:
        if event.sender_id in BRAIN_CHECKER:
            return
        if event.is_private and not (await event.get_sender()).bot:
            if not is_mongo_alive() or not is_redis_alive():
                return
            apprv = await approval(event.chat_id)

            # This part basically is a sanity check
            # If the message that sent before is Unapproved Message
            # then stop sending it again to prevent FloodHit
            if not apprv and event.text != UNAPPROVED_MSG:
                if event.chat_id in LASTMSG:
                    prevmsg = LASTMSG[event.chat_id]
                    # If the message doesn't same as previous one
                    # Send the Unapproved Message again
                    if event.text != prevmsg:
                        await event.reply(UNAPPROVED_MSG)
                    LASTMSG.update({event.chat_id: event.text})
                else:
                    await event.reply(UNAPPROVED_MSG)
                    LASTMSG.update({event.chat_id: event.text})

                if await notif_state() is False:
                    await event.client.send_read_acknowledge(event.chat_id)
                if event.chat_id not in COUNT_PM:
                    COUNT_PM.update({event.chat_id: 1})
                else:
                    COUNT_PM[event.chat_id] = COUNT_PM[event.chat_id] + 1

                if COUNT_PM[event.chat_id] > 4:
                    await event.respond(
                        "`You were spamming my master's PM, which I don't like.`"
                        " `I'mma Report Spam.`")

                    try:
                        del COUNT_PM[event.chat_id]
                        del LASTMSG[event.chat_id]
                    except KeyError:
                        if BOTLOG:
                            await event.client.send_message(
                                BOTLOG_CHATID,
                                "Count PM is seemingly going retard, plis restart bot!",
                            )
                        LOGS.info("CountPM wen't rarted boi")
                        return

                    await event.client(BlockRequest(event.chat_id))
                    await event.client(ReportSpamRequest(peer=event.chat_id))

                    if BOTLOG:
                        name = await event.client.get_entity(event.chat_id)
                        name0 = str(name.first_name)
                        await event.client.send_message(
                            BOTLOG_CHATID,
                            "[" + name0 + "](tg://user?id=" +
                            str(event.chat_id) + ")" +
                            " was just another retarded nibba",
                        )
Exemple #30
0
async def fedban_all(msg):
    if not is_mongo_alive() or not is_redis_alive():
        await msg.edit("`Database connections failing!`")
        return
    textx = await msg.get_reply_message()
    if textx:
        try:
            banreason = "[userbot] "
            banreason += banreason.join(msg.text.split(" ")[1:])
            if banreason == "[userbot]":
                raise TypeError
        except TypeError:
            banreason = "[userbot] fban"
    else:
        banid = msg.text.split(" ")[1]
        if banid.isnumeric():
            # if its a user id
            banid = int(banid)
        else:
            # deal wid the usernames
            if msg.message.entities is not None:
                probable_user_mention_entity = msg.message.entities[0]

            if isinstance(probable_user_mention_entity,
                          MessageEntityMentionName):
                ban_id = probable_user_mention_entity.user_id
        try:
            banreason = "[userbot] "
            banreason += banreason.join(msg.text.split(" ")[2:])
            if banreason == "[userbot]":
                raise TypeError
        except TypeError:
            banreason = "[userbot] fban"
        if "spam" in banreason:
            spamwatch = True
        else:
            spamwatch = False
    failed = dict()
    count = 1
    fbanlist = []
    x = (await get_fban())
    for i in x:
        fbanlist.append(i["chatid"])
    for bangroup in fbanlist:

        # Send to proof to Spamwatch in case it was spam
        # Spamwatch is a reputed fed fighting against spam on telegram

        if bangroup == -1001312712379:
            if spamwatch:
                if textx:
                    await textx.forward_to(-1001312712379)
                    # Tag him, coz we can't fban xd
                    await bot.send_message(-1001312712379, "@SitiSchu")
                else:
                    await msg.reply(
                        "`Spam message detected. But no reply message, can't forward to spamwatch`"
                    )
            continue
        async with bot.conversation(bangroup) as conv:
            await conv.send_message(f"!fban {banid} {banreason}")
            resp = await conv.get_response()
            await bot.send_read_acknowledge(conv.chat_id)
            if "Beginning federation ban " not in resp.text:
                failed[bangroup] = str(conv.chat_id)
            else:
                count += 1
                await msg.edit("`Fbanned on " + str(count) + " feds!`")
            # Sleep to avoid a floodwait.
            # Prevents floodwait if user is a fedadmin on too many feds
            await asyncio.sleep(0.2)
    if failed:
        failedstr = ""
        for i in failed.keys():
            failedstr += failed[i]
            failedstr += " "
        await msg.reply(f"`Failed to fban in {failedstr}`")
    else:
        await msg.reply("`Fbanned in all feds!`")