From aa46ab51ed2b0d028a03da9d72a63abf8b9e229a Mon Sep 17 00:00:00 2001 From: Gonzalo HQ063 Date: Tue, 14 Aug 2012 01:02:18 -0300 Subject: [PATCH] Allow catching multiple events with only one method This update allows a module to catch multple events in the same method using lists. It supports the * wildcard. Before the update, you must catch events one by one in differents methods. --- .gitignore | 2 ++ bot.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9bea4330f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/bot.py b/bot.py index 453dbc4d7..5c9d07b2e 100755 --- a/bot.py +++ b/bot.py @@ -108,8 +108,12 @@ def sub(pattern, self=self): func.thread = True if not hasattr(func, 'event'): - func.event = 'PRIVMSG' - else: func.event = func.event.upper() + func.event = ['PRIVMSG'] + else: + if isinstance(func.event, list): + func.event = [element.upper() for element in func.event] + else: + func.event = [func.event.upper()] if hasattr(func, 'rule'): if isinstance(func.rule, str): @@ -205,8 +209,8 @@ def dispatch(self, origin, args): items = self.commands[priority].items() for regexp, funcs in items: for func in funcs: - if event != func.event: continue - + if event not in func.event and '*' not in func.event: continue + if '!'+event in func.event: continue match = regexp.match(text) if match: if self.limit(origin, func): continue