Ejemplo n.º 1
0
def getplugins(bot, event, *args):
    """list all plugins loaded by the bot, and all available plugins"""

    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 = []
    all_plugins = plugins.retrieve_all_plugins(allow_underscore=True) or []
    loaded_plugins = plugins.get_configured_plugins(bot) or []

    lines.append("**{} loaded plugins (config.json)**".format(len(loaded_plugins)))

    for _plugin in sorted(loaded_plugins):
        lines.append("* {}".format(_plugin.replace("_", "\\_")))

    lines.append("**{} available plugins**".format(len(all_plugins)))

    for _plugin in sorted(all_plugins):
        if _plugin not in loaded_plugins:
            lines.append("* {}".format(_plugin.replace("_", "\\_")))

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
Ejemplo n.º 2
0
def getplugins(bot, event, *args):
    """list all plugins loaded by the bot, and all available plugins"""

    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 = []
    all_plugins = plugins.retrieve_all_plugins(allow_underscore=True) or []
    loaded_plugins = plugins.get_configured_plugins(bot) or []

    lines.append("**{} loaded plugins (config.json)**".format(
        len(loaded_plugins)))

    for _plugin in sorted(loaded_plugins):
        lines.append("* {}".format(_plugin.replace("_", "\\_")))

    lines.append("**{} available plugins**".format(len(all_plugins)))

    for _plugin in sorted(all_plugins):
        if _plugin not in loaded_plugins:
            lines.append("* {}".format(_plugin.replace("_", "\\_")))

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
Ejemplo n.º 3
0
def addplugin(bot, event, plugin, *args):
    """Adds a plugin to the bot, REQUIRES REBOOT
    /bot addplugin <pluginname>"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    if plugin not in loaded_plugins:
        if plugin in all_plugins:
            value = bot.config.get_by_path(["plugins"])
            if isinstance(value, list):
                value.append(plugin)
                bot.config.set_by_path(["plugins"], value)
                bot.config.save()

                # attempt to load the plugin
                try:
                    if plugins.load(bot, "plugins.{}".format(plugin)):
                        message = "<b><pre>{}</pre>: loaded</b>".format(
                            "plugins.{}".format(plugin))
                    else:
                        message = "<b><pre>{}</pre>: failed</b>".format(
                            "plugins.{}".format(plugin))

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

            else:
                message = "Error: Do <b>/bot config set plugins []</b> first"
        else:
            message = "Not a valid plugin name"
    else:
        message = "Plugin already loaded"
    yield from bot.coro_send_message(event.conv_id, message)
Ejemplo n.º 4
0
def addplugin(bot, event, plugin, *args):
    """Adds a plugin to the bot, REQUIRES REBOOT
    /bot addplugin <pluginname>"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    if plugin not in loaded_plugins:
        if plugin in all_plugins:
            value = bot.config.get_by_path(["plugins"])
            if isinstance(value, list):
                value.append(plugin)
                bot.config.set_by_path(["plugins"], value)
                bot.config.save()

                # attempt to load the plugin
                try:
                    if plugins.load(bot, "plugins.{}".format(plugin)):
                        message = "<b><pre>{}</pre>: loaded</b>".format("plugins.{}".format(plugin))
                    else:
                        message = "<b><pre>{}</pre>: failed</b>".format("plugins.{}".format(plugin))

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

            else:
                message = "Error: Do <b>/bot config set plugins []</b> first"
        else:
            message = "Not a valid plugin name"
    else:
        message = "Plugin already loaded"
    yield from bot.coro_send_message(event.conv_id, message)
Ejemplo n.º 5
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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
def addplugin(bot, event, plugin, *args):
    """loads a plugin on the bot and adds it to 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)

    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

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

    if plugin in loaded_plugins:
        lines.append('* already loaded on bot start')
    else:
        module_path = "plugins.{}".format(plugin)
        escaped_module_path = module_path.replace("_", "\\_")
        try:
            if plugins.load(bot, module_path):
                lines.append('* **loaded: {}**'.format(escaped_module_path))
            else:
                lines.append(
                    '* failed to load: {}'.format(escaped_module_path))
        except RuntimeError as e:
            lines.append('* error loading {}: {}'.format(
                escaped_module_path, str(e)))

    if plugin in config_plugins:
        lines.append('* already in config.json')
    else:
        config_plugins.append(plugin)
        bot.config.set_by_path(["plugins"], config_plugins)
        bot.config.save()
        lines.append('* **added to config.json**')

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
Ejemplo n.º 8
0
def addplugin(bot, event, plugin, *args):
    """loads a plugin on the bot and adds it to 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)

    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

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

    if plugin in loaded_plugins:
        lines.append('* already loaded on bot start')
    else:
        module_path = "plugins.{}".format(plugin)
        escaped_module_path = module_path.replace("_", "\\_")
        try:
            if plugins.load(bot, module_path):
                lines.append('* **loaded: {}**'.format(escaped_module_path))
            else:
                lines.append('* failed to load: {}'.format(escaped_module_path))
        except RuntimeError as e:
            lines.append('* error loading {}: {}'.format(escaped_module_path, str(e)))

    if plugin in config_plugins:
        lines.append('* already in config.json')
    else:
        config_plugins.append(plugin)
        bot.config.set_by_path(["plugins"], config_plugins)
        bot.config.save()
        lines.append('* **added to config.json**')

    yield from bot.coro_send_message(event.conv_id, "\n".join(lines))
Ejemplo n.º 9
0
def getplugins(bot, event, *args):
    """List all plugins loaded by the bot, and all available plugins"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    html = """The following plugins are loaded:<br />"""

    for plugin in loaded_plugins:
        html += "<b>{}</b><br />".format(plugin)

    html += """<br />Available plugins:<br />"""

    for plugin in all_plugins:
        if plugin not in loaded_plugins:
            html += "<i>{}</i><br />".format(plugin)

    yield from bot.coro_send_to_user_and_conversation(event.user_id.chat_id, event.conv_id, html, "<i>I've sent you a private message</i>")
Ejemplo n.º 10
0
def getplugins(bot, event, *args):
    """List all plugins loaded by the bot, and all available plugins"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    html = """The following plugins are loaded:<br />"""

    for plugin in loaded_plugins:
        html += "<b>{}</b><br />".format(plugin)

    html += """<br />Available plugins:<br />"""

    for plugin in all_plugins:
        if plugin not in loaded_plugins:
            html += "<i>{}</i><br />".format(plugin)

    yield from bot.coro_send_to_user_and_conversation(event.user_id.chat_id, event.conv_id, html, "<i>I've sent you a private message</i>")
Ejemplo n.º 11
0
def addplugin(bot, event, plugin, *args):
    """Adds a plugin to the bot, REQUIRES REBOOT
    /bot addplugin <pluginname>"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    if plugin not in loaded_plugins:
        if plugin in all_plugins:
            value = bot.config.get_by_path(["plugins"])
            if isinstance(value, list):
                value.append(plugin)
                bot.config.set_by_path(["plugins"], value)
                bot.config.save()
                yield from bot.coro_send_message(event.conv_id, "Plugin <i>{}</i> added".format(plugin))
            else:
                yield from bot.coro_send_message(event.conv_id, "Error: Do <b>/bot config set plugins []</b> first")
        else:
            yield from bot.coro_send_message(event.conv_id, "Not a valid plugin name")
    else:
        yield from bot.coro_send_message(event.conv_id, "Plugin already loaded")
Ejemplo n.º 12
0
def addplugin(bot, event, plugin, *args):
    """Adds a plugin to the bot, REQUIRES REBOOT
    /devilbot addplugin <pluginname>"""
    all_plugins = plugins.retrieve_all_plugins()
    loaded_plugins = plugins.get_configured_plugins(bot)

    if plugin not in loaded_plugins:
        if plugin in all_plugins:
            value = bot.config.get_by_path(["plugins"])
            if isinstance(value, list):
                value.append(plugin)
                bot.config.set_by_path(["plugins"], value)
                bot.config.save()
                yield from bot.coro_send_message(event.conv_id, "Plugin <i>{}</i> added".format(plugin))
            else:
                yield from bot.coro_send_message(event.conv_id, "Error: Do <b>/devilbot config set plugins []</b> first")
        else:
            yield from bot.coro_send_message(event.conv_id, "Not a valid plugin name")
    else:
        yield from bot.coro_send_message(event.conv_id, "Plugin already loaded")