LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.02k stars 1.41k forks source link

get_entity Cannot find any entity corresponding to “xxxx” #4128

Closed agoukuaile closed 1 year ago

agoukuaile commented 1 year ago

Code that causes the issue

client.get_entity('xxxx')

Now telegram allows four-character usernames, but this method fails to get any four-character usernames

Expected behavior

a channel info

Actual behavior

Cannot find any entity corresponding to “xxxx”

Traceback

No response

Telethon version

1.28.5

Python version

3.9.13

Operating system (including distribution name and version)

Windows 11

Other details

No response

Checklist

Lonami commented 1 year ago

Please include the traceback. As it stands, the error may be legit.

agoukuaile commented 1 year ago

@xxxx is a channel Now telegram allows 4 character usernames,in https://fragment.com/ we can buy 4 character username

in \telethon\utils.py file

VALID_USERNAME_RE = re.compile(
    r'^([a-z](?:(?!__)\w){3,30}[a-z\d]'
    r'|gif|vid|pic|bing|wiki|imdb|bold|vote|like|coub)$',
    re.IGNORECASE
)

change To

VALID_USERNAME_RE = re.compile(
    r'^([a-z](?:(?!__)\w){2,30}[a-z\d]'
    r'|gif|vid|pic)$',
    re.IGNORECASE
)
Lonami commented 1 year ago

The above commit should allow any username between 3 and 32 characters now (as long as there is no trailing underscore or two underscores together).

agoukuaile commented 1 year ago

VALID_USERNAME_RE = re.compile(
    r'^([a-z](?:(?!__)\w){3,30}[a-z\d]'
    r'|gif|vid|pic|bing|wiki|imdb|bold|vote|like|coub)$',
    re.IGNORECASE
)

def main(username):
    if VALID_USERNAME_RE.match(username):
        print ('match')
    else:
        print ('not match')

main('didi')

The content of the print of the above code is not match, I think this regularization is not correct

Lonami commented 1 year ago

You are likely not using the latest version. The above commit may not be in PyPi yet.