mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Merge branch 'develop' into future
# Conflicts: # pyrogram/__init__.py
This commit is contained in:
commit
fccadf526e
@ -1104,35 +1104,58 @@ 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:
|
|
||||||
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:
|
||||||
|
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
|
|
||||||
|
|
||||||
def save_file(self,
|
def save_file(self,
|
||||||
path: str,
|
path: str,
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user