summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/figlet.py6
-rw-r--r--plugins/rainbow.py6
-rw-r--r--src/plugin.py10
-rw-r--r--src/plugin_manager.py29
4 files changed, 18 insertions, 33 deletions
diff --git a/plugins/figlet.py b/plugins/figlet.py
index cf885352..52bbc67a 100644
--- a/plugins/figlet.py
+++ b/plugins/figlet.py
@@ -3,9 +3,9 @@ import subprocess
class Plugin(BasePlugin):
def init(self):
- self.add_poezio_event_handler('muc_say', self.figletize)
- self.add_poezio_event_handler('conversation_say', self.figletize)
- self.add_poezio_event_handler('private_say', self.figletize)
+ self.add_event_handler('muc_say', self.figletize)
+ self.add_event_handler('conversation_say', self.figletize)
+ self.add_event_handler('private_say', self.figletize)
def figletize(self, msg):
process = subprocess.Popen(['figlet', msg['body']], stdout=subprocess.PIPE)
diff --git a/plugins/rainbow.py b/plugins/rainbow.py
index 0f242027..8a73da03 100644
--- a/plugins/rainbow.py
+++ b/plugins/rainbow.py
@@ -12,9 +12,9 @@ def rand_color():
class Plugin(BasePlugin):
def init(self):
- self.add_poezio_event_handler('muc_say', self.rainbowize)
- self.add_poezio_event_handler('private_say', self.rainbowize)
- self.add_poezio_event_handler('conversation_say', self.rainbowize)
+ self.add_event_handler('muc_say', self.rainbowize)
+ self.add_event_handler('private_say', self.rainbowize)
+ self.add_event_handler('conversation_say', self.rainbowize)
def rainbowize(self, msg):
msg['body'] = ''.join(['%s%s' % (rand_color(),char,) for char in xhtml.clean_text(msg['body'])])
diff --git a/src/plugin.py b/src/plugin.py
index 80bc4dfc..c87ba2f1 100644
--- a/src/plugin.py
+++ b/src/plugin.py
@@ -79,14 +79,8 @@ class BasePlugin(object, metaclass=SafetyMetaclass):
def del_command(self, name):
return self.plugin_manager.del_command(self.__module__, name)
- def add_event_handler(self, event_name, handler):
- return self.plugin_manager.add_event_handler(self.__module__, event_name, handler)
+ def add_event_handler(self, event_name, handler, position=0):
+ return self.plugin_manager.add_event_handler(self.__module__, event_name, handler, position)
def del_event_handler(self, event_name, handler):
return self.plugin_manager.del_event_handler(self.__module__, event_name, handler)
-
- def add_poezio_event_handler(self, event_name, handler, position=0):
- return self.plugin_manager.add_poezio_event_handler(self.__module__, event_name, handler, position)
-
- def del_poezio_event_handler(self, event_name, handler):
- return self.plugin_manager.del_poezio_event_handler(self.__module__, event_name, handler)
diff --git a/src/plugin_manager.py b/src/plugin_manager.py
index bdf94a5b..067cb10e 100644
--- a/src/plugin_manager.py
+++ b/src/plugin_manager.py
@@ -34,7 +34,6 @@ class PluginManager(object):
self.plugins = {} # module name -> plugin object
self.commands = {} # module name -> dict of commands loaded for the module
self.event_handlers = {} # module name -> list of event_name/handler pairs loaded for the module
- self.poezio_event_handlers = {}
def load(self, name):
if name in self.plugins:
@@ -61,7 +60,6 @@ class PluginManager(object):
self.modules[name] = module
self.commands[name] = {}
self.event_handlers[name] = []
- self.poezio_event_handlers[name] = []
self.plugins[name] = module.Plugin(self, self.core, plugins_conf_dir)
def unload(self, name):
@@ -70,15 +68,12 @@ class PluginManager(object):
for command in self.commands[name].keys():
del self.core.commands[command]
for event_name, handler in self.event_handlers[name]:
- self.core.xmpp.del_event_handler(event_name, handler)
- for handler in self.poezio_event_handlers[name]:
- self.core.events.del_event_handler(None, handler)
+ self.del_event_handler(name, event_name, handler)
self.plugins[name].unload()
del self.plugins[name]
del self.commands[name]
del self.event_handlers[name]
- del self.poezio_event_handlers[name]
except Exception as e:
import traceback
self.core.information(_("Could not unload plugin (may not be safe to try again): ") + traceback.format_exc())
@@ -97,26 +92,22 @@ class PluginManager(object):
commands[name] = (handler, help, completion)
self.core.commands[name] = (handler, help, completion)
- def add_event_handler(self, module_name, event_name, handler):
+ def add_event_handler(self, module_name, event_name, handler, position=0):
eh = self.event_handlers[module_name]
eh.append((event_name, handler))
- self.core.xmpp.add_event_handler(event_name, handler)
+ if event_name in self.core.events.events:
+ self.core.events.add_event_handler(event_name, handler, position)
+ else:
+ self.core.xmpp.add_event_handler(event_name, handler)
def del_event_handler(self, module_name, event_name, handler):
- self.core.xmpp.del_event_handler(event_name, handler)
+ if event_name in self.core.events.events:
+ self.core.events.del_event_handler(None, handler)
+ else:
+ self.core.xmpp.del_event_handler(event_name, handler)
eh = self.event_handlers[module_name]
eh = list(filter(lambda e : e != (event_name, handler), eh))
- def add_poezio_event_handler(self, module_name, event_name, handler, position):
- eh = self.poezio_event_handlers[module_name]
- eh.append(handler)
- self.core.events.add_event_handler(event_name, handler, position)
-
- def del_poezio_event_handler(self, module_name, event_name, handler):
- self.core.events.del_event_handler(None, handler)
- eh = self.poezio_event_handlers[module_name]
- eh = list(filter(lambda e : e != handler, eh))
-
def completion_load(self, the_input):
"""
completion function that completes the name of the plugins, from