2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Small dispatcher clean ups

This commit is contained in:
Dan 2018-10-18 21:18:22 +02:00
parent 38ff950d01
commit 09e0345868

View File

@ -50,6 +50,7 @@ class Dispatcher:
def __init__(self, client, workers): def __init__(self, client, workers):
self.client = client self.client = client
self.workers = workers self.workers = workers
self.workers_list = [] self.workers_list = []
self.updates = Queue() self.updates = Queue()
self.groups = OrderedDict() self.groups = OrderedDict()
@ -69,8 +70,8 @@ class Dispatcher:
for _ in range(self.workers): for _ in range(self.workers):
self.updates.put(None) self.updates.put(None)
for i in self.workers_list: for worker in self.workers_list:
i.join() worker.join()
self.workers_list.clear() self.workers_list.clear()
@ -83,8 +84,8 @@ class Dispatcher:
def remove_handler(self, handler, group: int): def remove_handler(self, handler, group: int):
if group not in self.groups: if group not in self.groups:
raise ValueError("Group {} does not exist. " raise ValueError("Group {} does not exist. Handler was not removed.".format(group))
"Handler was not removed.".format(group))
self.groups[group].remove(handler) self.groups[group].remove(handler)
def update_worker(self): def update_worker(self):
@ -108,8 +109,7 @@ class Dispatcher:
if isinstance(update.message, types.MessageEmpty): if isinstance(update.message, types.MessageEmpty):
continue continue
message = utils.parse_messages(self.client, update.message, users, chats) update = utils.parse_messages(self.client, update.message, users, chats), MessageHandler
update = message, MessageHandler
elif isinstance(update, Dispatcher.DELETE_MESSAGE_UPDATES): elif isinstance(update, Dispatcher.DELETE_MESSAGE_UPDATES):
deleted_messages = utils.parse_deleted_messages( deleted_messages = utils.parse_deleted_messages(