Exemple #1
0
async def load_all_plugins():
    success = 0
    total = 0
    p_error = ''
    async for _file in userge.search_messages(PLUGINS_CHAT_ID,
                                              filter="document"):
        total += 1
        file_ = _file.document
        if file_.file_name.endswith('.py') and file_.file_size < 2**20:
            if not os.path.isdir(Config.TMP_PATH):
                os.makedirs(Config.TMP_PATH)
            t_path = os.path.join(Config.TMP_PATH, file_.file_name)
            if os.path.isfile(t_path):
                os.remove(t_path)
            await _file.download(file_name=t_path)
            plugin = get_import_path(ROOT, t_path)
            try:
                await userge.load_plugin(plugin, reload_plugin=True)
                await userge.finalize_load()
            except (ImportError, SyntaxError, NameError) as i_e:
                os.remove(t_path)
                p_error += f'\n\n**PLUGIN:** `{file_.file_name}`\n**ERROR:** `{i_e}`'
            else:
                success += 1
                _LOG.info(f"Loaded {plugin}")
    return (success, total, p_error)
Exemple #2
0
async def load_cmd_handler(message: Message):
    await message.edit("Loading...")
    replied = message.reply_to_message
    if replied and replied.document:
        file_ = replied.document

        if file_.file_name.endswith('.py') and file_.file_size < 1024**1024:
            path = await replied.download(file_name="userge/plugins/temp/")
            plugin = get_import_path(ROOT, path)

            try:
                userge.load_plugin(plugin)

            except ImportError as i_e:
                os.remove(path)
                await message.err(i_e)

            else:
                await message.edit(f"`Loaded {plugin}`", del_in=3, log=True)

        else:
            await message.edit("`Plugin Not Found`")

    else:
        await message.edit("`Reply to Plugin`")
Exemple #3
0
def get_all_plugins() -> List[str]:
    """list all plugins"""
    plugins = get_import_path(
        ROOT,
        "/dev/" if len(sys.argv) == 2 and sys.argv[1] == "dev" else "/**/")
    _LOG.debug("All Available Plugins: %s", plugins)
    return list(plugins)
Exemple #4
0
async def load_cmd_handler(message: Message):
    await message.edit("Loading...")
    replied = message.reply_to_message
    if replied and replied.document:
        file_ = replied.document

        if file_.file_name.endswith('.py') and file_.file_size < 2**20:
            if not os.path.isdir(TMP_PATH):
                os.makedirs(TMP_PATH)

            t_path = os.path.join(TMP_PATH, file_.file_name)
            if os.path.isfile(t_path):
                os.remove(t_path)

            await replied.download(file_name=t_path)
            plugin = get_import_path(ROOT, t_path)

            try:
                userge.load_plugin(plugin)

            except (ImportError, SyntaxError) as i_e:
                os.remove(t_path)
                await message.err(i_e)

            else:
                await message.edit(f"`Loaded {plugin}`",
                                   del_in=3,
                                   log=__name__)

        else:
            await message.edit("`Plugin Not Found`")

    else:
        await message.edit("`Reply to Plugin`")
Exemple #5
0
def get_all_plugins() -> List[str]:
    """list all plugins"""

    plugins = get_import_path(ROOT, "/**/")

    LOG.debug("All Available Plugins: %s", plugins)

    return list(plugins)
Exemple #6
0
async def loadall(msg: Message) -> None:
    if not PLUGINS_CHAT_ID:
        await msg.edit("Add `PLUGINS_CHAT_ID` var to Load Plugins from Plugins Channel")
        return
    await msg.edit("`Loading All Plugin(s)...`")
    success = 0
    total = 0
    p_error = ""
    async for _file in msg.client.search_messages(PLUGINS_CHAT_ID, filter="document"):
        total += 1
        file_ = _file.document
        if file_.file_name.endswith(".py") and file_.file_size < 2 ** 20:
            if not os.path.isdir(Config.TMP_PATH):
                os.makedirs(Config.TMP_PATH)
            t_path = os.path.join(Config.TMP_PATH, file_.file_name)
            if os.path.isfile(t_path):
                os.remove(t_path)
            await _file.download(file_name=t_path)
            plugin = get_import_path(ROOT, t_path)
            try:
                await userge.load_plugin(plugin, reload_plugin=True)
                await userge.finalize_load()
            except (ImportError, SyntaxError, NameError) as i_e:
                os.remove(t_path)
                p_error += f"\n\n**PLUGIN:** `{file_.file_name}`\n**ERROR:** `{i_e}`"
            else:
                success += 1
                _LOG.info(f"Loaded {plugin}")
    if success:
        if success == total:
            await msg.edit("`Loaded all Plugin(s)`")
        else:
            await msg.edit(
                f"`{success} Plugin(s) loaded from {total}`\n__see log channel for more info__"
            )
            await _CHANNEL.log(p_error)
    else:
        await msg.edit(
            f"`0 Plugin(s) loaded from {total}`\n__see log channel for more info__"
        )
        await _CHANNEL.log(p_error)
Exemple #7
0
async def load(message: Message) -> None:
    """ load plugins, commands, filters """
    if message.flags:
        if not message.filtered_input_str:
            await message.err("name required!")
            return
        await message.edit("`Loading...`")
        names_ = message.filtered_input_str.split(" ")
        type_ = list(message.flags)
        if "p" in type_:
            found = set(names_).intersection(set(userge.manager.plugins))
            if found:
                out = await userge.manager.load_plugins(list(found))
                if out:
                    out_str = "**--Loaded Plugin(s)--**\n\n"
                    for plg_name, cmds in out.items():
                        out_str += f"**{plg_name}** : `{'`,    `'.join(cmds)}`\n"
                else:
                    out_str = f"already loaded! : `{'`,    `'.join(names_)}`"
            else:
                await message.err(f"plugins : {', '.join(names_)} not found!")
                return
        elif "c" in type_:
            for t_name in names_:
                if not t_name.startswith(Config.CMD_TRIGGER):
                    names_.append(Config.CMD_TRIGGER + t_name)
            found = set(names_).intersection(set(userge.manager.commands))
            if found:
                out = await userge.manager.load_commands(list(found))
                if out:
                    out_str = "**--Loaded Command(s)--**\n\n"
                    out_str += f"`{'`,    `'.join(out)}`"
                else:
                    out_str = f"already loaded! : `{'`,    `'.join(names_)}`"
            else:
                await message.err(f"commands : {', '.join(names_)} not found!")
                return
        elif "f" in type_:
            found = set(names_).intersection(set(userge.manager.filters))
            if found:
                out = await userge.manager.load_filters(list(found))
                if out:
                    out_str = "**--Loaded Filter(s)--**\n\n"
                    out_str += f"`{'`,    `'.join(out)}`"
                else:
                    out_str = f"already loaded! : `{'`,    `'.join(names_)}`"
            else:
                await message.err(f"filters : {', '.join(names_)} not found!")
                return
        else:
            await message.err("invalid input flag!")
            return
        await message.edit(out_str, del_in=0, log=__name__)
    else:
        await message.edit("`Loading...`")
        replied = message.reply_to_message
        if replied and replied.document:
            file_ = replied.document
            if file_.file_name.endswith(".py") and file_.file_size < 2**20:
                if not os.path.isdir(Config.TMP_PATH):
                    os.makedirs(Config.TMP_PATH)
                t_path = os.path.join(Config.TMP_PATH, file_.file_name)
                if os.path.isfile(t_path):
                    os.remove(t_path)
                await replied.download(file_name=t_path)
                plugin = get_import_path(ROOT, t_path)
                try:
                    await userge.load_plugin(plugin, reload_plugin=True)
                    await userge.finalize_load()
                except (ImportError, SyntaxError, NameError) as i_e:
                    os.remove(t_path)
                    await message.err(i_e)
                else:
                    await message.edit(f"`Loaded {plugin}`",
                                       del_in=3,
                                       log=__name__)
            else:
                await message.edit("`Plugin Not Found`")
        else:
            await message.edit(f"pls check `{Config.CMD_TRIGGER}help load` !")
Exemple #8
0
def get_all_plugins():
    plugins = get_import_path(ROOT, "/**/")

    LOG.info(f"all plugins: {plugins}")

    return plugins
Exemple #9
0
def get_all_plugins() -> List[str]:
    """ list all plugins """
    plugins = get_import_path(ROOT, "/" if len(sys.argv) == 2 and sys.argv[1] == 'dev' else "/**/")
    _LOG.debug("%s : Mevcut Tüm Eklentiler", plugins)
    return list(plugins)
Exemple #10
0
def get_all_plugins():
    plugins = get_import_path(ROOT, "/**/")

    LOG.debug(f"Plugins to Load: {plugins}")

    return plugins