diff options
-rwxr-xr-x | fot.py | 8 | ||||
-rw-r--r-- | modules/url_titles.py | 3 |
2 files changed, 10 insertions, 1 deletions
@@ -57,6 +57,7 @@ class Bot(irc.IRCClient): bots.append(self) self.modules = {} self.keywords = {} + self.msg_callbacks = [] def __repr__(self): return '<Bot %s@%s>' % (self.nickname, self.factory.server) @@ -66,6 +67,10 @@ class Bot(irc.IRCClient): raise Exception('Keyword "%s" already in use' % kw) self.keywords[kw] = mod + def register_callback(self, mod): + if not mod in self.msg_callbacks: + self.msg_callbacks.append(mod) + def apply_modules(self): # Call stop() for each module if neccessary (can't rely on __del__ here) for m in self.modules.itervalues(): @@ -86,6 +91,9 @@ class Bot(irc.IRCClient): self.join(chan) def privmsg(self, nick, channel, msg): + for mod in self.msg_callbacks: + mod.privmsg(nick, channel, msg) + msg = msg.split(None, 1) if not len(msg): return diff --git a/modules/url_titles.py b/modules/url_titles.py index d5408ce..3172fac 100644 --- a/modules/url_titles.py +++ b/modules/url_titles.py @@ -15,6 +15,7 @@ class Module: def __init__(self, bot): self.irc = bot + self.irc.register_callback(self) def spotify(self, s): try: @@ -137,7 +138,7 @@ class Module: s += '\002[%d]\002 %s ' % (i+1, format_text(titles[i])) return s.strip() - def __call__(self, nick, channel, msg): + def privmsg(self, nick, channel, msg): titles = self.get_titles(msg) if titles: self.irc.msg(channel if not channel == self.irc.nickname else nick.split('!')[0], titles) |