ircbot: provide feedback option to _plugin_unload

This commit is contained in:
Brian S. Stephan 2016-01-17 09:49:55 -06:00
parent 10071f9094
commit 97c18a2459
1 changed files with 6 additions and 3 deletions

View File

@ -686,7 +686,7 @@ class IRCBot(irc.client.SimpleIRCClient):
log.debug("calling _unload_plugin on %s", plugin_path)
self._unload_plugin(connection, event, plugin_path)
def _unload_plugin(self, connection, event, plugin_path):
def _unload_plugin(self, connection, event, plugin_path, feedback=True):
"""Attempt to unload and del a module if it's loaded.
This stops the plugin, which should (if it's coded properly) disconnect its
@ -698,6 +698,8 @@ class IRCBot(irc.client.SimpleIRCClient):
:type event: Event
:param plugin_path: path (likely a relative one) of the plugin to attempt to unload
:type plugin_path: str
:param feedback: whether or not to send messages to IRC regarding the unload attempt
:type feedback: bool
"""
log.debug("trying to unload plugin %s", plugin_path)
@ -718,9 +720,10 @@ class IRCBot(irc.client.SimpleIRCClient):
del plugin
del sys.modules[plugin_path]
self.privmsg(dest, "Plugin '{0:s}' unloaded.".format(plugin_path))
if feedback:
self.privmsg(dest, "Plugin '{0:s}' unloaded.".format(plugin_path))
if not unloaded:
if not unloaded and feedback:
self.privmsg(dest, "Plugin '{0:s}' is not loaded.".format(plugin_path))
# loop over the sys.modules entries, for debugging