def activate_plugin(self, name): try: if name in get_all_active_plugin_names(): return "Plugin already in active list" if name not in get_all_plugin_names(): return "I don't know this %s plugin" % name activate_plugin_by_name(name) except Exception as e: logger.exception("Error loading %s" % name) return '%s failed to start : %s\n' % (name, e) get_plugin_obj_by_name(name).callback_connect() return "Plugin %s activated" % name
def unload(self, mess, args): """unload a plugin""" args = args.strip() if not args: return ("Please tell me which of the following plugin to reload:\n" "{}".format(holder.bot.formatted_plugin_list(active_only=False))) if args not in get_all_plugin_names(): return ("{} isn't a valid plugin names. The current plugin are:\n" "{}".format(args, holder.bot.formatted_plugin_list(active_only=False))) if args not in get_all_active_plugin_names(): return "{} is not currently loaded".format(args) return holder.bot.deactivate_plugin(args)
def formatted_plugin_list(active_only=True): """ Return a formatted, plain-text list of loaded plugins. When active_only=True, this will only return plugins which are actually active. Otherwise, it will also include inactive (blacklisted) plugins. """ if active_only: all_plugins = get_all_active_plugin_names() else: all_plugins = get_all_plugin_names() return "\n".join(("- " + plugin for plugin in all_plugins))
def reload(self, mess, args): """reload a plugin""" args = args.strip() if not args: yield ("Please tell me which of the following plugin to reload:\n" "{}".format(holder.bot.formatted_plugin_list(active_only=False))) return if args not in get_all_plugin_names(): yield ("{} isn't a valid plugin names. The current plugin are:\n" "{}".format(args, holder.bot.formatted_plugin_list(active_only=False))) return yield holder.bot.deactivate_plugin(args) # Not needed but keeps the feedback to user consistent reload_plugin_by_name(args) yield holder.bot.activate_plugin(args)
def unblacklist(self, mess, args): """Remove a plugin from the blacklist""" if args not in get_all_plugin_names(): return ("{} isn't a valid plugin names. The current plugins are:\n" "{}".format(args, holder.bot.formatted_plugin_list(active_only=False))) return holder.bot.unblacklist_plugin(args)
def blacklist(self, mess, args): """Blacklist a plugin so that it will not be loaded automatically during bot startup""" if args not in get_all_plugin_names(): return ("{} isn't a valid plugin names. The current plugins are:\n" "{}".format(args, holder.bot.formatted_plugin_list(active_only=False))) return holder.bot.blacklist_plugin(args)