Example #1
0
async def command_interface(event):
    try:
        message = event.message
        prefix = "send"
        if message.is_reply:
            prefix = "reply"
        if message.out:
            return
        from_id = message.from_id
        to_id = message.to_id
        if event.is_private:
            pr = utilities.prGreen
        else:
            pr = utilities.prPurple
        if message.text and not message.via_bot_id:
            pr(
                str(from_id) + ": " + prefix + " text message : " +
                message.text + " to " + str(to_id))
        elif message.media and not message.via_bot_id:
            pr(
                str(from_id) + ": " + prefix + " media message to " +
                str(to_id))
        elif message.via_bot_id:
            pr(
                str(from_id) + ": " + prefix + " inline message to " +
                str(to_id))
        else:
            utilities.prRed(
                str(from_id) + ": " + prefix + " unknown message to " +
                str(to_id))
    except Exception as e:
        print(str(e))
Example #2
0
async def addDev_user(message, from_id):
    try:
        if getDevUser(from_id):
            return await message.reply("User already added as Dev.")
        addDevUser(from_id)
        utilities.devs.append(from_id)
        return await message.reply("❏︙تم رفع مطور")
    except Exception as e:
        utilities.prRed(str(type(e)) + " Error : " + str(e))
        return await message.reply(str(e))
Example #3
0
async def remDev_user(message, from_id):
    try:
        if not getDevUser(from_id):
            return await message.reply("User already not dev.")
        remDevUser(from_id)
        utilities.devs.remove(from_id)
        return await message.reply("❏︙تم تنزيل مطور")
    except Exception as e:
        utilities.prRed(str(type(e)) + " Error : " + str(e))
        return await message.reply(str(e))
Example #4
0
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))
Example #5
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))
Example #6
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))