From 1178536288f6853ebc6bacd8dcc5e79edf435f7a Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 18 Apr 2003 08:24:04 +0000 Subject: [PATCH] Added Combine, a callback to combine two Privmsg callbacks (most often Privmsg and PrivmsgRegexp) --- src/callbacks.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/callbacks.py b/src/callbacks.py index 28a9435cb..76b509240 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -454,4 +454,42 @@ class PrivmsgRegexp(Privmsg): irc = IrcObjectProxyRegexp(irc) self.callCommand(method, irc, msg, m) + +class Combine: + def __getattr__(self, attr): + for cls in self.classes: + if hasattr(cls, attr): + return getattr(cls, attr) + raise AttributeError, attr + + def __init__(self, *args, **kwargs): + self.instances = [] + for cls in self.classes: + self.instances.append(cls(*args, **kwargs)) + + def __call__(self, irc, msg): + for instance in self.instances: + instance.__call__(irc, msg) + + def inFilter(self, irc, msg): + for instance in self.instances: + msg = instance.inFilter(irc, msg) + return msg + + def outFilter(self, irc, msg): + for instance in self.instances: + msg = instance.outFilter(irc, msg) + + def name(self): + return 'Combine(%s)' % \ + ','.join([cls.__name__ for cls in self.classes]) + + def reset(self): + for instance in instances: + instance.reset() + + def die(self): + for instance in instances: + instance.die() + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: