Beispiel #1
0
async def unload_command(msg, args):
    name = plugin_from_arg(args.next_arg())
    if not name: return
    try:
        plugins.unload(name)
        await msg.channel.send("\u2705")
    except:
        await reply_exception(msg)
Beispiel #2
0
def removeplugin(bot, event, plugin, *args):
    """unloads a plugin from the bot and removes it from the config, does not require plugins. prefix"""

    config_plugins = bot.config.get_by_path(["plugins"]) or False
    if not isinstance(config_plugins, list):
        yield from bot.coro_send_message(
            event.conv_id,
            "this command only works with manually-configured plugins key in config.json"
        )
        return

    lines = []
    loaded_plugins = plugins.get_configured_plugins(bot) or []
    all_plugins = plugins.retrieve_all_plugins(allow_underscore=True)

    lines.append("**remove plugin: {}**".format(plugin.replace("_", "\\_")))

    plugin = _strip_plugin_path(plugin)

    if not plugin:
        yield from bot.coro_send_message(event.conv_id, "invalid plugin name")
        return

    if plugin not in all_plugins:
        yield from bot.coro_send_message(
            event.conv_id,
            "plugin does not exist: {}".format(plugin.replace("_", "\\_")))
        return

    if plugin in loaded_plugins:
        try:
            module_path = "plugins.{}".format(plugin)
            escaped_module_path = module_path.replace("_", "\\_")
            yield from plugins.unload(bot, module_path)
            lines.append('* **unloaded: {}**'.format(escaped_module_path))
        except (RuntimeError, KeyError) as e:
            lines.append('* error unloading {}: {}'.format(
                escaped_module_path, str(e)))
    else:
        lines.append('* not loaded on bot start')

    if plugin in config_plugins:
        config_plugins.remove(plugin)
        bot.config.set_by_path(["plugins"], config_plugins)
        bot.config.save()
        lines.append('* **removed from config.json**')
    else:
        lines.append('* not in config.json')

    if len(lines) == 1:
        lines = [
            "no action was taken for {}".format(plugin.replace("_", "\\_"))
        ]

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
def removeplugin(bot, event, plugin, *args):
    """unloads a plugin from the bot and removes it from the config, does not require plugins. prefix"""

    config_plugins = bot.config.get_by_path(["plugins"]) or False
    if not isinstance(config_plugins, list):
        yield from bot.coro_send_message(
            event.conv_id,
            "this command only works with manually-configured plugins key in config.json")
        return

    lines = []
    loaded_plugins = plugins.get_configured_plugins(bot) or []
    all_plugins = plugins.retrieve_all_plugins(allow_underscore=True)

    lines.append("**remove plugin: {}**".format(plugin.replace("_", "\\_")))

    plugin = _strip_plugin_path(plugin)

    if not plugin:
        yield from bot.coro_send_message(
            event.conv_id,
            "invalid plugin name")
        return

    if plugin not in all_plugins:
        yield from bot.coro_send_message(
            event.conv_id,
            "plugin does not exist: {}".format(plugin.replace("_", "\\_")) )
        return

    if plugin in loaded_plugins:
        try:
            module_path = "plugins.{}".format(plugin)
            escaped_module_path = module_path.replace("_", "\\_")
            yield from plugins.unload(bot, module_path)
            lines.append('* **unloaded: {}**'.format(escaped_module_path))
        except (RuntimeError, KeyError) as e:
            lines.append('* error unloading {}: {}'.format(escaped_module_path, str(e)))
    else:
        lines.append('* not loaded on bot start')

    if plugin in config_plugins:
        config_plugins.remove(plugin)
        bot.config.set_by_path(["plugins"], config_plugins)
        bot.config.save()
        lines.append('* **removed from config.json**')
    else:
        lines.append('* not in config.json')

    if len(lines) == 1:
        lines = [ "no action was taken for {}".format(plugin.replace("_", "\\_")) ]

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
def pluginunload(bot, event, *args):
    if args:
        module_path = args[0]

        try:
            yield from plugins.unload(bot, module_path)
            message = "<b><pre>{}</pre>: unloaded</b>".format(module_path)

        except (RuntimeError, KeyError) as e:
            message = "<b><pre>{}</pre>: <pre>{}</pre></b>".format(module_path, str(e))

    else:
        message = "<b>module path required</b>"

    yield from bot.coro_send_message(event.conv_id, message)
def pluginreload(bot, event, *args):
    """reloads a previously loaded plugin, requires plugins. prefix"""

    if args:
        module_path = args[0]

        try:
            yield from plugins.unload(bot, module_path)
            if plugins.load(bot, module_path):
                message = "<b><pre>{}</pre>: reloaded</b>".format(module_path)
            else:
                message = "<b><pre>{}</pre>: failed reload</b>".format(module_path)

        except (RuntimeError, KeyError) as e:
            message = "<b><pre>{}</pre>: <pre>{}</pre></b>".format(module_path, str(e))

    else:
        message = "<b>module path required</b>"

    yield from bot.coro_send_message(event.conv_id, message)
def pluginreload(bot, event, *args):
    """reloads a previously loaded plugin, requires plugins. prefix"""

    if args:
        module_path = args[0]

        try:
            yield from plugins.unload(bot, module_path)
            if plugins.load(bot, module_path):
                message = "<b><pre>{}</pre>: reloaded</b>".format(module_path)
            else:
                message = "<b><pre>{}</pre>: failed reload</b>".format(module_path)

        except (RuntimeError, KeyError) as e:
            message = "<b><pre>{}</pre>: <pre>{}</pre></b>".format(module_path, str(e))

    else:
        message = "<b>module path required</b>"

    yield from bot.coro_send_message(event.conv_id, message)
Beispiel #7
0
def removeplugin(bot, event, plugin, *args):
    """Removes a plugin from the bot, REQUIRES REBOOT
    /bot removeplugin <pluginname>"""
    value = bot.config.get_by_path(["plugins"])
    if isinstance(value, list):
        try:
            value.remove(plugin)
            bot.config.set_by_path(["plugins"], value)
            bot.config.save()

            yield from plugins.unload(bot, "plugins.{}".format(plugin))
            message = "<b><pre>{}</pre>: unloaded</b>".format("plugins.{}".format(plugin))
        except ValueError:
            message = "Plugin not loaded"
        except (RuntimeError, KeyError) as e:
            message = "<b><pre>{}</pre>: <pre>{}</pre></b>".format("plugins.{}".format(plugin), str(e))
    else:
        message = "Plugin config not set"


    yield from bot.coro_send_message(event.conv_id, message)
def removeplugin(bot, event, plugin, *args):
    """Removes a plugin from the bot, REQUIRES REBOOT
    /bot removeplugin <pluginname>"""
    value = bot.config.get_by_path(["plugins"])
    if isinstance(value, list):
        try:
            value.remove(plugin)
            bot.config.set_by_path(["plugins"], value)
            bot.config.save()

            yield from plugins.unload(bot, "plugins.{}".format(plugin))
            message = "<b><pre>{}</pre>: unloaded</b>".format(
                "plugins.{}".format(plugin))
        except ValueError:
            message = "Plugin not loaded"
        except (RuntimeError, KeyError) as e:
            message = "<b><pre>{}</pre>: <pre>{}</pre></b>".format(
                "plugins.{}".format(plugin), str(e))
    else:
        message = "Plugin config not set"

    yield from bot.coro_send_message(event.conv_id, message)
Beispiel #9
0
 def close(self):
     """deregister the handlers to send and receive messages"""
     if self._closed:
         return
     asyncio.ensure_future(plugins.unload(self.uid))
     self._closed = True