Skip to content

Commit

Permalink
Rewrite command dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 22, 2016
1 parent f6a9edb commit 44bab05
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions bot.py
Expand Up @@ -249,36 +249,32 @@ def dispatch(self, origin, args):
for priority in ('high', 'medium', 'low'):
items = self.commands[priority].items()
for regexp, funcs in items:
match = regexp.match(text)
if not match: continue
for func in funcs:
if event != func.event and func.event != '*': continue
if self.limit(origin, func): continue

phenny = self.wrapped(origin, text, match)
input = self.input(origin, text, bytes, match, event, args)

# Run all hooks and abort processing if one of them returns False
if not func.nohook and any(not hook(phenny, input, func) for hook in self.hooks):
continue

if func.thread:
targs = (func, origin, phenny, input)
t = threading.Thread(target=self.call, args=targs)
t.start()
else:
self.call(func, origin, phenny, input)

for source in [origin.sender, origin.nick]:
try:
self.stats[(func.name, source)] += 1
except KeyError:
self.stats[(func.name, source)] = 1

match = regexp.match(text)
if match:
if self.limit(origin, func): continue

phenny = self.wrapped(origin, text, match)
input = self.input(origin, text, bytes, match, event, args)

if not func.nohook:
# Run all hooks and abort processing if one of them returns False
abort = False
for hook in self.hooks:
if not hook(phenny, input, func):
abort = True
break
if abort:
break

if func.thread:
targs = (func, origin, phenny, input)
t = threading.Thread(target=self.call, args=targs)
t.start()
else: self.call(func, origin, phenny, input)

for source in [origin.sender, origin.nick]:
try: self.stats[(func.name, source)] += 1
except KeyError:
self.stats[(func.name, source)] = 1

if __name__ == '__main__':
print(__doc__)

0 comments on commit 44bab05

Please sign in to comment.