mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-05 00:35:10 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/__init__.py # pyrogram/client/client.py
This commit is contained in:
@@ -162,7 +162,7 @@ yourself. This allows you to test your filter by pressing the inline button:
|
|||||||
"username", # Change this to your username or id
|
"username", # Change this to your username or id
|
||||||
"Pyrogram's custom filter test",
|
"Pyrogram's custom filter test",
|
||||||
reply_markup=InlineKeyboardMarkup(
|
reply_markup=InlineKeyboardMarkup(
|
||||||
[[InlineKeyboardButton("Press me", "pyrogram")]]
|
[[InlineKeyboardButton("Press me", b"pyrogram")]]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ containing "pyrogram" as data:
|
|||||||
|
|
||||||
hardcoded_data = Filters.create(
|
hardcoded_data = Filters.create(
|
||||||
name="HardcodedData",
|
name="HardcodedData",
|
||||||
func=lambda filter, callback_query: callback_query.data == "pyrogram"
|
func=lambda filter, callback_query: callback_query.data == b"pyrogram"
|
||||||
)
|
)
|
||||||
|
|
||||||
The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same
|
The ``lambda`` operator in python is used to create small anonymous functions and is perfect for this example, the same
|
||||||
@@ -187,7 +187,7 @@ could be achieved with a normal function, but we don't really need it as it make
|
|||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
def func(filter, callback_query):
|
def func(filter, callback_query):
|
||||||
return callback_query.data == "pyrogram"
|
return callback_query.data == b"pyrogram"
|
||||||
|
|
||||||
hardcoded_data = Filters.create(
|
hardcoded_data = Filters.create(
|
||||||
name="HardcodedData",
|
name="HardcodedData",
|
||||||
@@ -223,6 +223,6 @@ And its usage:
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@app.on_callback_query(dynamic_data("pyrogram"))
|
@app.on_callback_query(dynamic_data(b"pyrogram"))
|
||||||
def pyrogram_data(client, callback_query):
|
def pyrogram_data(client, callback_query):
|
||||||
client.answer_callback_query(callback_query.id, "it works!")
|
client.answer_callback_query(callback_query.id, "it works!")
|
@@ -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.3.async"
|
__version__ = "0.9.4.asyncio"
|
||||||
|
|
||||||
from .api.errors import Error
|
from .api.errors import Error
|
||||||
from .client.types import (
|
from .client.types import (
|
||||||
|
@@ -1102,35 +1102,56 @@ class Client(Methods, BaseClient):
|
|||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
``KeyError`` in case the peer doesn't exist in the internal database.
|
``KeyError`` in case the peer doesn't exist in the internal database.
|
||||||
"""
|
"""
|
||||||
if type(peer_id) is str:
|
try:
|
||||||
if peer_id in ("self", "me"):
|
|
||||||
return types.InputPeerSelf()
|
|
||||||
|
|
||||||
peer_id = re.sub(r"[@+\s]", "", peer_id.lower())
|
|
||||||
|
|
||||||
try:
|
|
||||||
int(peer_id)
|
|
||||||
except ValueError:
|
|
||||||
if peer_id not in self.peers_by_username:
|
|
||||||
await self.send(functions.contacts.ResolveUsername(peer_id))
|
|
||||||
|
|
||||||
return self.peers_by_username[peer_id]
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
return self.peers_by_phone[peer_id]
|
|
||||||
except KeyError:
|
|
||||||
raise PeerIdInvalid
|
|
||||||
|
|
||||||
try: # User
|
|
||||||
return self.peers_by_id[peer_id]
|
return self.peers_by_id[peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try: # Chat
|
if type(peer_id) is str:
|
||||||
return self.peers_by_id[-peer_id]
|
if peer_id in ("self", "me"):
|
||||||
|
return types.InputPeerSelf()
|
||||||
|
|
||||||
|
peer_id = re.sub(r"[@+\s]", "", peer_id.lower())
|
||||||
|
|
||||||
|
try:
|
||||||
|
int(peer_id)
|
||||||
|
except ValueError:
|
||||||
|
if peer_id not in self.peers_by_username:
|
||||||
|
await self.send(functions.contacts.ResolveUsername(username=peer_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.peers_by_username[peer_id]
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return self.peers_by_phone[peer_id]
|
||||||
|
except KeyError:
|
||||||
|
raise PeerIdInvalid
|
||||||
|
|
||||||
|
if peer_id > 0:
|
||||||
|
self.fetch_peers(
|
||||||
|
self.send(
|
||||||
|
functions.users.GetUsers(
|
||||||
|
id=[types.InputUser(peer_id, 0)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if str(peer_id).startswith("-100"):
|
||||||
|
self.send(
|
||||||
|
functions.channels.GetChannels(
|
||||||
|
id=[types.InputChannel(int(str(peer_id)[4:]), 0)]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.send(
|
||||||
|
functions.messages.GetChats(
|
||||||
|
id=[-peer_id]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return self.peers_by_id[peer_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try: # Channel
|
raise PeerIdInvalid
|
||||||
return self.peers_by_id[int("-100" + str(peer_id))]
|
|
||||||
except (KeyError, ValueError):
|
|
||||||
raise PeerIdInvalid
|
|
||||||
|
|
||||||
async def save_file(self,
|
async def save_file(self,
|
||||||
path: str,
|
path: str,
|
||||||
|
@@ -86,37 +86,37 @@ class Filters:
|
|||||||
"""Filter edited messages."""
|
"""Filter edited messages."""
|
||||||
|
|
||||||
audio = create("Audio", lambda _, m: bool(m.audio))
|
audio = create("Audio", lambda _, m: bool(m.audio))
|
||||||
"""Filter messages that contain :obj:`Audio <pyrogram.api.types.pyrogram.Audio>` objects."""
|
"""Filter messages that contain :obj:`Audio <pyrogram.Audio>` objects."""
|
||||||
|
|
||||||
document = create("Document", lambda _, m: bool(m.document))
|
document = create("Document", lambda _, m: bool(m.document))
|
||||||
"""Filter messages that contain :obj:`Document <pyrogram.api.types.pyrogram.Document>` objects."""
|
"""Filter messages that contain :obj:`Document <pyrogram.Document>` objects."""
|
||||||
|
|
||||||
photo = create("Photo", lambda _, m: bool(m.photo))
|
photo = create("Photo", lambda _, m: bool(m.photo))
|
||||||
"""Filter messages that contain :obj:`Photo <pyrogram.api.types.pyrogram.PhotoSize>` objects."""
|
"""Filter messages that contain :obj:`Photo <pyrogram.PhotoSize>` objects."""
|
||||||
|
|
||||||
sticker = create("Sticker", lambda _, m: bool(m.sticker))
|
sticker = create("Sticker", lambda _, m: bool(m.sticker))
|
||||||
"""Filter messages that contain :obj:`Sticker <pyrogram.api.types.pyrogram.Sticker>` objects."""
|
"""Filter messages that contain :obj:`Sticker <pyrogram.Sticker>` objects."""
|
||||||
|
|
||||||
animation = create("GIF", lambda _, m: bool(m.animation))
|
animation = create("GIF", lambda _, m: bool(m.animation))
|
||||||
"""Filter messages that contain :obj:`Animation <pyrogram.api.types.pyrogram.Animation>` objects."""
|
"""Filter messages that contain :obj:`Animation <pyrogram.Animation>` objects."""
|
||||||
|
|
||||||
video = create("Video", lambda _, m: bool(m.video))
|
video = create("Video", lambda _, m: bool(m.video))
|
||||||
"""Filter messages that contain :obj:`Video <pyrogram.api.types.pyrogram.Video>` objects."""
|
"""Filter messages that contain :obj:`Video <pyrogram.Video>` objects."""
|
||||||
|
|
||||||
voice = create("Voice", lambda _, m: bool(m.voice))
|
voice = create("Voice", lambda _, m: bool(m.voice))
|
||||||
"""Filter messages that contain :obj:`Voice <pyrogram.api.types.pyrogram.Voice>` note objects."""
|
"""Filter messages that contain :obj:`Voice <pyrogram.Voice>` note objects."""
|
||||||
|
|
||||||
video_note = create("Voice", lambda _, m: bool(m.video_note))
|
video_note = create("Voice", lambda _, m: bool(m.video_note))
|
||||||
"""Filter messages that contain :obj:`VideoNote <pyrogram.api.types.pyrogram.VideoNote>` objects."""
|
"""Filter messages that contain :obj:`VideoNote <pyrogram.VideoNote>` objects."""
|
||||||
|
|
||||||
contact = create("Contact", lambda _, m: bool(m.contact))
|
contact = create("Contact", lambda _, m: bool(m.contact))
|
||||||
"""Filter messages that contain :obj:`Contact <pyrogram.api.types.pyrogram.Contact>` objects."""
|
"""Filter messages that contain :obj:`Contact <pyrogram.Contact>` objects."""
|
||||||
|
|
||||||
location = create("Location", lambda _, m: bool(m.location))
|
location = create("Location", lambda _, m: bool(m.location))
|
||||||
"""Filter messages that contain :obj:`Location <pyrogram.api.types.pyrogram.Location>` objects."""
|
"""Filter messages that contain :obj:`Location <pyrogram.Location>` objects."""
|
||||||
|
|
||||||
venue = create("Venue", lambda _, m: bool(m.venue))
|
venue = create("Venue", lambda _, m: bool(m.venue))
|
||||||
"""Filter messages that contain :obj:`Venue <pyrogram.api.types.pyrogram.Venue>` objects."""
|
"""Filter messages that contain :obj:`Venue <pyrogram.Venue>` objects."""
|
||||||
|
|
||||||
web_page = create("WebPage", lambda _, m: m.web_page)
|
web_page = create("WebPage", lambda _, m: m.web_page)
|
||||||
"""Filter messages sent with a webpage preview."""
|
"""Filter messages sent with a webpage preview."""
|
||||||
|
@@ -16,8 +16,11 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.client.filters.filter import Filter
|
from pyrogram.client.filters.filter import Filter
|
||||||
|
from pyrogram.client.handlers.handler import Handler
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +48,7 @@ class OnMessage(BaseClient):
|
|||||||
The group identifier, defaults to 0.
|
The group identifier, defaults to 0.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(func):
|
def decorator(func: callable) -> Tuple[Handler, int]:
|
||||||
if isinstance(func, tuple):
|
if isinstance(func, tuple):
|
||||||
func = func[0].callback
|
func = func[0].callback
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user