make it possible for a module to respond and tell irclib to stop calling other handlers.

this works via Module.reply(). if it produces IRC output, it returns
"NO MORE", which is returned by do(), which is returned by the handler,
which instructs irclib to cease calling handlers. now all we need
is some priorities for the modules (also supported by irclib) and
we may be in business
This commit is contained in:
Brian S. Stephan 2011-01-07 00:44:31 -06:00
parent a451eceef3
commit 8bec2e62a1
1 changed files with 5 additions and 3 deletions

View File

@ -166,7 +166,7 @@ class Module(object):
what = addressed_re.sub('', what) what = addressed_re.sub('', what)
try: try:
self.do(connection, event, nick, userhost, replypath, what, admin_unlocked) return self.do(connection, event, nick, userhost, replypath, what, admin_unlocked)
except Exception as e: except Exception as e:
print('EXCEPTION: ' + str(e)) print('EXCEPTION: ' + str(e))
@ -201,11 +201,11 @@ class Module(object):
return return
try: try:
self.do(connection, event, nick, userhost, replypath, what, admin_unlocked) return self.do(connection, event, nick, userhost, replypath, what, admin_unlocked)
except Exception as e: except Exception as e:
print('EXCEPTION: ' + str(e)) print('EXCEPTION: ' + str(e))
def reply(self, connection, replypath, replystr): def reply(self, connection, replypath, replystr, stop_responding=True):
""" """
Reply over IRC to replypath or return a string with the reply. Reply over IRC to replypath or return a string with the reply.
Utility method to do the proper type of reply (either to IRC, or as a return Utility method to do the proper type of reply (either to IRC, or as a return
@ -220,6 +220,8 @@ class Module(object):
return replystr return replystr
else: else:
connection.privmsg(replypath, replystr) connection.privmsg(replypath, replystr)
if stop_responding:
return "NO MORE"
def remove_metaoptions(self, list): def remove_metaoptions(self, list):
"""Remove metaoptions from provided list, which was probably from a config file.""" """Remove metaoptions from provided list, which was probably from a config file."""