DrBotIRC: clean up event handlers a bit

this brings them more in line with the code in irclib, which will be
nice since i'm using that code as basis f or additions in a later commit
This commit is contained in:
Brian S. Stephan 2012-12-20 09:50:20 -06:00
parent 891b2bcab8
commit 53a3c40102
1 changed files with 17 additions and 7 deletions

View File

@ -288,9 +288,12 @@ class DrBotIRC(irclib.IRC):
self.try_alias(connection, event)
h = self.handlers
for handler in h.get("all_events", []) + h.get(event.eventtype(), []):
th = sorted(h.get('all_events', []) + h.get(event.eventtype(), []))
for handler in th:
try:
if handler[1](connection, event) == "NO MORE":
prio, method = handler
ret = method(connection, event)
if ret == 'NO MORE':
return
except Exception as e:
log.error("exception floated up to DrBotIrc!")
@ -330,13 +333,20 @@ class DrBotIRC(irclib.IRC):
"""
h = self.handlers
replies = []
for handler in h.get("all_events", []) + h.get(event.eventtype(), []):
ret = handler[1](connection, event)
if ret:
replies.append(ret)
h = self.handlers
th = sorted(h.get('all_events', []) + h.get(event.eventtype(), []))
for handler in th:
try:
prio, method = handler
ret = method(connection, event)
if ret:
replies.append(ret)
except Exception as e:
log.error("exception floated up to DrBotIrc!")
log.exception(e)
if len(replies):
event.arguments()[0] = '\n'.join(replies)