From 53a3c401029d6f6dcd46b0caa4b68d2cd6285ad9 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 20 Dec 2012 09:50:20 -0600 Subject: [PATCH] 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 --- DrBotIRC.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/DrBotIRC.py b/DrBotIRC.py index bcad038..ae0c95b 100644 --- a/DrBotIRC.py +++ b/DrBotIRC.py @@ -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)