From 4ac8f86156831a00f56754803c8871916cb2139b Mon Sep 17 00:00:00 2001 From: Noam Meltzer Date: Mon, 25 Apr 2016 10:18:26 +0300 Subject: [PATCH] dispatcher: honour the priority of groups --- telegram/ext/dispatcher.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/telegram/ext/dispatcher.py b/telegram/ext/dispatcher.py index f9027cc7e..95f0e87c0 100644 --- a/telegram/ext/dispatcher.py +++ b/telegram/ext/dispatcher.py @@ -96,6 +96,9 @@ class Dispatcher(object): self.update_queue = update_queue self.handlers = {} + """:type: dict[int, list[Handler]""" + self.groups = [] + """:type: list[int]""" self.error_handlers = [] self.logger = logging.getLogger(__name__) @@ -170,8 +173,8 @@ class Dispatcher(object): self.dispatchError(None, update) else: - for group in self.handlers.values(): - for handler in group: + for group in self.groups: + for handler in self.handlers[group]: try: if handler.checkUpdate(update): handler.handleUpdate(update, self) @@ -220,6 +223,8 @@ class Dispatcher(object): if group not in self.handlers: self.handlers[group] = list() + self.groups.append(group) + self.groups = sorted(self.groups) self.handlers[group].append(handler)