mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-30 13:57:54 +00:00
Merge branch 'develop'
This commit is contained in:
@@ -82,7 +82,7 @@ If no error shows up you are good to go.
|
|||||||
|
|
||||||
>>> import pyrogram
|
>>> import pyrogram
|
||||||
>>> pyrogram.__version__
|
>>> pyrogram.__version__
|
||||||
'0.9.1'
|
'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
|
||||||
|
@@ -23,7 +23,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"
|
__version__ = "0.9.3"
|
||||||
|
|
||||||
from .api.errors import Error
|
from .api.errors import Error
|
||||||
from .client.types import (
|
from .client.types import (
|
||||||
|
@@ -851,7 +851,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((update, updates.users, updates.chats))
|
self.dispatcher.updates_queue.put((update, updates.users, updates.chats))
|
||||||
elif isinstance(updates, (types.UpdateShortMessage, types.UpdateShortChatMessage)):
|
elif isinstance(updates, (types.UpdateShortMessage, types.UpdateShortChatMessage)):
|
||||||
diff = self.send(
|
diff = self.send(
|
||||||
functions.updates.GetDifference(
|
functions.updates.GetDifference(
|
||||||
@@ -862,7 +862,7 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if diff.new_messages:
|
if diff.new_messages:
|
||||||
self.dispatcher.updates.put((
|
self.dispatcher.updates_queue.put((
|
||||||
types.UpdateNewMessage(
|
types.UpdateNewMessage(
|
||||||
message=diff.new_messages[0],
|
message=diff.new_messages[0],
|
||||||
pts=updates.pts,
|
pts=updates.pts,
|
||||||
@@ -872,9 +872,9 @@ class Client(Methods, BaseClient):
|
|||||||
diff.chats
|
diff.chats
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
self.dispatcher.updates.put((diff.other_updates[0], [], []))
|
self.dispatcher.updates_queue.put((diff.other_updates[0], [], []))
|
||||||
elif isinstance(updates, types.UpdateShort):
|
elif isinstance(updates, types.UpdateShort):
|
||||||
self.dispatcher.updates.put((updates.update, [], []))
|
self.dispatcher.updates_queue.put((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:
|
||||||
|
@@ -52,17 +52,15 @@ 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.workers_list = []
|
self.workers_list = []
|
||||||
self.updates = Queue()
|
self.updates_queue = Queue()
|
||||||
self.groups = OrderedDict()
|
self.groups = OrderedDict()
|
||||||
|
|
||||||
Dispatcher.UPDATES = {
|
self.update_parsers = {
|
||||||
Dispatcher.MESSAGE_UPDATES:
|
Dispatcher.MESSAGE_UPDATES:
|
||||||
lambda upd, usr, cht: (utils.parse_messages(self.client, upd.message, usr, cht), MessageHandler),
|
lambda upd, usr, cht: (utils.parse_messages(self.client, upd.message, usr, cht), MessageHandler),
|
||||||
|
|
||||||
@@ -76,7 +74,7 @@ class Dispatcher:
|
|||||||
lambda upd, usr, cht: (utils.parse_user_status(upd.status, upd.user_id), UserStatusHandler)
|
lambda upd, usr, cht: (utils.parse_user_status(upd.status, upd.user_id), UserStatusHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
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}
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
for i in range(self.workers):
|
for i in range(self.workers):
|
||||||
@@ -91,7 +89,7 @@ class Dispatcher:
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
for _ in range(self.workers):
|
for _ in range(self.workers):
|
||||||
self.updates.put(None)
|
self.updates_queue.put(None)
|
||||||
|
|
||||||
for worker in self.workers_list:
|
for worker in self.workers_list:
|
||||||
worker.join()
|
worker.join()
|
||||||
@@ -116,7 +114,7 @@ class Dispatcher:
|
|||||||
log.debug("{} started".format(name))
|
log.debug("{} started".format(name))
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
update = self.updates.get()
|
update = self.updates_queue.get()
|
||||||
|
|
||||||
if update is None:
|
if update is None:
|
||||||
break
|
break
|
||||||
@@ -126,7 +124,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
|
||||||
|
@@ -68,7 +68,7 @@ class Message(Object):
|
|||||||
new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created,
|
new_chat_photo, delete_chat_photo, group_chat_created, supergroup_chat_created, channel_chat_created,
|
||||||
migrate_to_chat_id, migrate_from_chat_id, pinned_message.
|
migrate_to_chat_id, migrate_from_chat_id, pinned_message.
|
||||||
|
|
||||||
media (``bool``` *optional*):
|
media (``bool`` *optional*):
|
||||||
The message is a media message.
|
The message is a media message.
|
||||||
A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation,
|
A media message has one and only one of these fields set: audio, document, photo, sticker, video, animation,
|
||||||
voice, video_note, contact, location, venue.
|
voice, video_note, contact, location, venue.
|
||||||
@@ -391,7 +391,7 @@ class Message(Object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def edit(self, text: str, parse_mode: str = "", disable_web_page_preview: bool = None, reply_markup=None):
|
def edit(self, text: str, parse_mode: str = "", disable_web_page_preview: bool = None, reply_markup=None):
|
||||||
"""Bound method *edit* of :obj:`Message <pyrogram.Message>
|
"""Bound method *edit* of :obj:`Message <pyrogram.Message>`
|
||||||
|
|
||||||
Use as a shortcut for:
|
Use as a shortcut for:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user