mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-18 05:30:15 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/__init__.py # pyrogram/client/client.py # pyrogram/client/dispatcher/dispatcher.py
This commit is contained in:
commit
d5ef03d662
@ -82,7 +82,7 @@ If no error shows up you are good to go.
|
|||||||
|
|
||||||
>>> import pyrogram
|
>>> import pyrogram
|
||||||
>>> pyrogram.__version__
|
>>> pyrogram.__version__
|
||||||
'0.9.2'
|
'0.9.3'
|
||||||
|
|
||||||
.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto
|
.. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto
|
||||||
.. _develop: http://github.com/pyrogram/pyrogram
|
.. _develop: http://github.com/pyrogram/pyrogram
|
||||||
|
@ -31,7 +31,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance
|
|||||||
"e" if sys.getfilesystemencoding() != "utf-8" else "\xe8"
|
"e" if sys.getfilesystemencoding() != "utf-8" else "\xe8"
|
||||||
)
|
)
|
||||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||||
__version__ = "0.9.2.async"
|
__version__ = "0.9.3.async"
|
||||||
|
|
||||||
from .api.errors import Error
|
from .api.errors import Error
|
||||||
from .client.types import (
|
from .client.types import (
|
||||||
|
@ -850,7 +850,7 @@ class Client(Methods, BaseClient):
|
|||||||
if len(self.channels_pts[channel_id]) > 50:
|
if len(self.channels_pts[channel_id]) > 50:
|
||||||
self.channels_pts[channel_id] = self.channels_pts[channel_id][25:]
|
self.channels_pts[channel_id] = self.channels_pts[channel_id][25:]
|
||||||
|
|
||||||
self.dispatcher.updates.put_nowait((update, updates.users, updates.chats))
|
self.dispatcher.updates_queue.put_nowait((update, updates.users, updates.chats))
|
||||||
elif isinstance(updates, (types.UpdateShortMessage, types.UpdateShortChatMessage)):
|
elif isinstance(updates, (types.UpdateShortMessage, types.UpdateShortChatMessage)):
|
||||||
diff = await self.send(
|
diff = await self.send(
|
||||||
functions.updates.GetDifference(
|
functions.updates.GetDifference(
|
||||||
@ -861,7 +861,7 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if diff.new_messages:
|
if diff.new_messages:
|
||||||
self.dispatcher.updates.put_nowait((
|
self.dispatcher.updates_queue.put_nowait((
|
||||||
types.UpdateNewMessage(
|
types.UpdateNewMessage(
|
||||||
message=diff.new_messages[0],
|
message=diff.new_messages[0],
|
||||||
pts=updates.pts,
|
pts=updates.pts,
|
||||||
@ -871,9 +871,9 @@ class Client(Methods, BaseClient):
|
|||||||
diff.chats
|
diff.chats
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
self.dispatcher.updates.put_nowait((diff.other_updates[0], [], []))
|
self.dispatcher.updates_queue.put_nowait((diff.other_updates[0], [], []))
|
||||||
elif isinstance(updates, types.UpdateShort):
|
elif isinstance(updates, types.UpdateShort):
|
||||||
self.dispatcher.updates.put_nowait((updates.update, [], []))
|
self.dispatcher.updates_queue.put_nowait((updates.update, [], []))
|
||||||
elif isinstance(updates, types.UpdatesTooLong):
|
elif isinstance(updates, types.UpdatesTooLong):
|
||||||
log.warning(updates)
|
log.warning(updates)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -50,14 +50,12 @@ class Dispatcher:
|
|||||||
|
|
||||||
MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES
|
MESSAGE_UPDATES = NEW_MESSAGE_UPDATES + EDIT_MESSAGE_UPDATES
|
||||||
|
|
||||||
UPDATES = None
|
|
||||||
|
|
||||||
def __init__(self, client, workers: int):
|
def __init__(self, client, workers: int):
|
||||||
self.client = client
|
self.client = client
|
||||||
self.workers = workers
|
self.workers = workers
|
||||||
|
|
||||||
self.update_worker_tasks = []
|
self.update_worker_tasks = []
|
||||||
self.updates = asyncio.Queue()
|
self.updates_queue = asyncio.Queue()
|
||||||
self.groups = OrderedDict()
|
self.groups = OrderedDict()
|
||||||
|
|
||||||
async def message_parser(update, users, chats):
|
async def message_parser(update, users, chats):
|
||||||
@ -72,14 +70,14 @@ class Dispatcher:
|
|||||||
async def user_status_parser(update, users, chats):
|
async def user_status_parser(update, users, chats):
|
||||||
return utils.parse_user_status(update.status, update.user_id), UserStatusHandler
|
return utils.parse_user_status(update.status, update.user_id), UserStatusHandler
|
||||||
|
|
||||||
Dispatcher.UPDATES = {
|
self.update_parsers = {
|
||||||
Dispatcher.MESSAGE_UPDATES: message_parser,
|
Dispatcher.MESSAGE_UPDATES: message_parser,
|
||||||
Dispatcher.DELETE_MESSAGE_UPDATES: deleted_messages_parser,
|
Dispatcher.DELETE_MESSAGE_UPDATES: deleted_messages_parser,
|
||||||
Dispatcher.CALLBACK_QUERY_UPDATES: callback_query_parser,
|
Dispatcher.CALLBACK_QUERY_UPDATES: callback_query_parser,
|
||||||
(types.UpdateUserStatus,): user_status_parser
|
(types.UpdateUserStatus,): user_status_parser
|
||||||
}
|
}
|
||||||
|
|
||||||
Dispatcher.UPDATES = {key: value for key_tuple, value in Dispatcher.UPDATES.items() for key in key_tuple}
|
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
for i in range(self.workers):
|
for i in range(self.workers):
|
||||||
@ -91,7 +89,7 @@ class Dispatcher:
|
|||||||
|
|
||||||
async def stop(self):
|
async def stop(self):
|
||||||
for i in range(self.workers):
|
for i in range(self.workers):
|
||||||
self.updates.put_nowait(None)
|
self.updates_queue.put_nowait(None)
|
||||||
|
|
||||||
for i in self.update_worker_tasks:
|
for i in self.update_worker_tasks:
|
||||||
await i
|
await i
|
||||||
@ -115,7 +113,7 @@ class Dispatcher:
|
|||||||
|
|
||||||
async def update_worker(self):
|
async def update_worker(self):
|
||||||
while True:
|
while True:
|
||||||
update = await self.updates.get()
|
update = await self.updates_queue.get()
|
||||||
|
|
||||||
if update is None:
|
if update is None:
|
||||||
break
|
break
|
||||||
@ -125,7 +123,7 @@ class Dispatcher:
|
|||||||
chats = {i.id: i for i in update[2]}
|
chats = {i.id: i for i in update[2]}
|
||||||
update = update[0]
|
update = update[0]
|
||||||
|
|
||||||
parser = Dispatcher.UPDATES.get(type(update), None)
|
parser = self.update_parsers.get(type(update), None)
|
||||||
|
|
||||||
if parser is None:
|
if parser is None:
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user