mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-17 03:51:05 +03:00
Allow using parenthesis or spaces in phones when .get_entity
This commit is contained in:
parent
5b6f9b6542
commit
71b6e527a6
|
@ -3,6 +3,8 @@ from datetime import datetime, timedelta
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import socks
|
import socks
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -852,10 +854,10 @@ class TelegramClient(TelegramBareClient):
|
||||||
return self(GetChannelsRequest([input_entity]))[0]
|
return self(GetChannelsRequest([input_entity]))[0]
|
||||||
|
|
||||||
if isinstance(entity, str):
|
if isinstance(entity, str):
|
||||||
if entity.startswith('+') or entity.isdigit():
|
stripped_phone = re.sub(r'[+-()\s]', '', entity)
|
||||||
|
if stripped_phone.isdigit():
|
||||||
contacts = self(GetContactsRequest(0))
|
contacts = self(GetContactsRequest(0))
|
||||||
try:
|
try:
|
||||||
stripped_phone = entity.strip('+')
|
|
||||||
return next(
|
return next(
|
||||||
u for u in contacts.users
|
u for u in contacts.users
|
||||||
if u.phone and u.phone.endswith(stripped_phone)
|
if u.phone and u.phone.endswith(stripped_phone)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user