Remove poezio_event_handler to keep only event_handler

This commit is contained in:
mathieui 2011-11-09 14:02:17 +01:00
parent 04c283c551
commit 98b9506983
4 changed files with 18 additions and 33 deletions

View file

@ -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)

View file

@ -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'])])

View file

@ -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)

View file

@ -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