コード例 #1
0
async def mute_user(message, from_id, chat_id, name):
    try:
        if getMutedUser(chat_id, from_id):
            return await message.reply("❏︙تم كتم العضو سابقن ")
        await utilities.client.edit_permissions(chat_id,
                                                from_id,
                                                send_messages=False)
        addMuteUser(chat_id, escape(name), from_id)
        return await message.reply("❏︙تم كتم العضو بنجاح")
    except errors.ChatAdminRequiredError as e:
        return await message.reply("Make me admin in group first.")
    except errors.UserAdminInvalidError:
        return await message.reply("Do not use it with admin dude.")
    except Exception as e:
        utilities.prRed(str(type(e)) + " Error : " + str(e))
        return await message.reply(str(e))
コード例 #2
0
ファイル: mutePersonal.py プロジェクト: WhitePrime/botsssh
async def unmute_user(message, from_id, chat_id):
    try:
        if not getMutedUser(chat_id, from_id):
            return await message.reply("User already unmuted.")
        await utilities.client.edit_permissions(chat_id,
                                                from_id,
                                                send_messages=True)
        remMuteUser(chat_id, from_id)
        return await message.reply("User unmuted successfully.")
    except errors.ChatAdminRequiredError as e:
        return await message.reply("Make me admin in group first.")
    except errors.UserAdminInvalidError:
        return await message.reply("Do not use it with admin dude.")
    except Exception as e:
        utilities.prRed(str(type(e)) + " Error : " + str(e))
        return await message.reply(str(e))
コード例 #3
0
async def my_event_handler(event):
    plugins = utilities.plugins
    try:
        message = event.message
        chat_id = event.chat_id
        from_id = event.sender_id
        mutedUsers = getMutedUser(chat_id, from_id)
        if mutedUsers:
            remMuteUser(chat_id, from_id)
        if message.text:
            matches = re.findall("^[#/!](cancel)$", event.raw_text,
                                 re.IGNORECASE)
            if len(matches) > 0 and matches[0] == "cancel":
                if from_id in utilities.user_steps:
                    del utilities.user_steps[from_id]
                    return await message.reply("Canceling successfully !")
        if from_id in utilities.user_steps:
            for plugin in plugins:
                if plugin["name"] == utilities.user_steps[from_id]["name"]:
                    for pattern in plugin["patterns"]:
                        if re.search(pattern, event.raw_text,
                                     re.IGNORECASE | re.MULTILINE):
                            matches = re.findall(pattern, event.raw_text,
                                                 re.IGNORECASE | re.DOTALL)
                            break
                        else:
                            matches = ["xxxxxxxxxx"]
                    if plugin["sudo"]:
                        if check_sudo(from_id):
                            return_values = await plugin["run"](
                                message,
                                matches[0],
                                chat_id,
                                utilities.user_steps[from_id]["step"],
                            )
                            for return_value in return_values:
                                if return_value:
                                    await (return_value)
                        else:
                            return
                    else:
                        return_values = await plugin["run"](
                            message,
                            matches[0],
                            chat_id,
                            utilities.user_steps[from_id]["step"],
                        )
                        if return_values:
                            for return_value in return_values:
                                await (return_value)
                    break
            return
        elif message.text is not None:
            for plugin in plugins:
                for pattern in plugin["patterns"]:
                    if re.search(pattern, event.raw_text,
                                 re.IGNORECASE | re.MULTILINE):
                        if ("bot" in plugin and
                                utilities.config["isbot"] != plugin["bot"]):
                            if plugin["bot"]:
                                await event.reply("for bot-api only")
                            else:
                                await event.reply("for bot-cli only")
                            return
                        matches = re.findall(
                            pattern,
                            event.raw_text,
                            re.IGNORECASE | re.MULTILINE | re.DOTALL,
                        )
                        if plugin["sudo"]:
                            if check_sudo(event.sender_id):
                                return_values = await plugin["run"](
                                    event,
                                    matches[0],
                                    chat_id,
                                    0,
                                    crons=utilities.crons)

                                for return_value in return_values:
                                    if return_value:
                                        await (return_value)
                            else:
                                return

                        else:
                            return_values = await plugin["run"](
                                event,
                                matches[0],
                                chat_id,
                                0,
                                crons=utilities.crons)
                            if return_values:
                                for return_value in return_values:
                                    await (return_value)
        elif message.media is not None or message.file is not None:
            match = ""
            if message.photo:
                match = "__photo__"
            if message.gif:
                match = "__gif__"
            for plugin in plugins:
                for pattern in plugin["patterns"]:
                    if re.search(pattern, match, re.IGNORECASE | re.MULTILINE):
                        matches = re.findall(pattern, "__photo__",
                                             re.IGNORECASE)
                        if plugin["sudo"]:
                            if check_sudo(event.sender_id):
                                return_values = await plugin["run"](event,
                                                                    matches[0],
                                                                    chat_id, 0)
                                for return_value in return_values:
                                    if return_value:
                                        await (return_value)
                            else:
                                return
                        else:
                            return_values = await plugin["run"](event,
                                                                matches[0],
                                                                chat_id, 0)
                            if return_values:
                                for return_value in return_values:
                                    await (return_value)

    except Exception as e:
        print(str(e))
        await event.reply("Error : " + str(e))
コード例 #4
0
async def my_event_handler(event):
    try:
        message = event.message
        chat_id = event.chat_id
        from_id = event.sender_id
        plugins = utilities.plugins
        mutedUsers = getMutedUser(chat_id, from_id)
        if mutedUsers:
            remMuteUser(chat_id, from_id)
        if message.raw_text:
            matches = re.findall("^[#/!](cancel)$", event.raw_text,
                                 re.IGNORECASE)
            if len(matches) > 0 and matches[0] == "cancel":
                if from_id in utilities.user_steps:
                    del utilities.user_steps[from_id]
                    return await message.reply("Canceling successfully !")
        if from_id in utilities.user_steps:
            for plugin in plugins:
                if plugin["name"] == utilities.user_steps[from_id]["name"]:
                    for pattern in plugin["patterns"]:
                        if re.search(pattern, event.raw_text,
                                     re.IGNORECASE | re.MULTILINE):
                            matches = re.findall(pattern, event.raw_text,
                                                 re.IGNORECASE | re.DOTALL)
                            break
                        else:
                            matches = ["xxxxxxxxxx"]
                    if plugin["sudo"]:
                        if utilities.check_sudo(from_id):
                            return_values = await plugin["run"](
                                message,
                                matches[0],
                                chat_id,
                                utilities.user_steps[from_id]["step"],
                            )
                            for return_value in return_values:
                                if return_value:
                                    try:
                                        await (return_value)
                                    except Exception as e:
                                        print("step :" + str(e))
                        else:
                            return
                    else:
                        return_values = await plugin["run"](
                            message,
                            matches[0],
                            chat_id,
                            utilities.user_steps[from_id]["step"],
                        )
                        if return_values:
                            for return_value in return_values:
                                await (return_value)
                    break
            return
        elif message.raw_text is not None and message.raw_text != "":
            if "flood" not in utilities.config:
                utilities.config["flood"] = True
                utilities.save_config()
            if utilities.config["flood"]:
                pv = utilities.red.get("flood-" + str(message.sender_id)) or 0
                # print("flood-" + str(message.sender_id), pv)
                if pv == 0:
                    utilities.flood[message.sender_id] = True
                utilities.red.set("flood-" + str(message.sender_id),
                                  (int(pv) + 1),
                                  ex=1)
                if (int(pv) + 1) == 5 and utilities.flood[message.sender_id]:
                    await message.reply("please do not flood...")
                    utilities.prRed(
                        str(message.sender_id) +
                        " : is causing flood please stop...")
                    utilities.flood[message.sender_id] = False
                    return
                elif (int(pv) + 1) >= 5:
                    return
            for plugin in plugins:
                for pattern in plugin["patterns"]:
                    if re.search(pattern, event.raw_text,
                                 re.IGNORECASE | re.MULTILINE):
                        if ("bot" in plugin and
                                utilities.config["isbot"] != plugin["bot"]):
                            if plugin["bot"]:
                                await event.reply("for bot-api only")
                            else:
                                await event.reply("for bot-cli only")
                            return
                        matches = re.findall(
                            pattern,
                            event.raw_text,
                            re.IGNORECASE | re.MULTILINE | re.DOTALL,
                        )
                        if plugin["sudo"]:
                            if utilities.check_sudo(event.sender_id):
                                return_values = await plugin["run"](
                                    event,
                                    matches[0],
                                    chat_id,
                                    0,
                                    crons=utilities.crons)

                                for return_value in return_values:
                                    if return_value:
                                        try:
                                            await (return_value)
                                        except Exception as e:
                                            print("text main :" + str(e))
                            else:
                                continue

                        else:
                            return_values = await plugin["run"](
                                event,
                                matches[0],
                                chat_id,
                                0,
                                crons=utilities.crons)
                            if return_values:
                                for return_value in return_values:
                                    await (return_value)
        elif message.media is not None or message.file is not None:
            match = ""
            if message.photo:
                match = "__photo__"
            if message.gif:
                match = "__gif__"
            for plugin in plugins:
                for pattern in plugin["patterns"]:
                    if re.search(pattern, match, re.IGNORECASE | re.MULTILINE):
                        matches = re.findall(pattern, match, re.IGNORECASE)
                        if plugin["sudo"]:
                            if utilities.check_sudo(event.sender_id):
                                return_values = await plugin["run"](event,
                                                                    matches[0],
                                                                    chat_id, 0)
                                for return_value in return_values:
                                    try:
                                        await (return_value)
                                    except Exception as e:
                                        print("media :" + str(e))
                            else:
                                return
                        else:
                            return_values = await plugin["run"](event,
                                                                matches[0],
                                                                chat_id, 0)
                            if return_values:
                                for return_value in return_values:
                                    await (return_value)

    except Exception as e:
        print(str(e))
        await event.reply("Error : " + str(e))