mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-20 12:06:37 +00:00
Add a force_fetch parameter to .get_entity
This commit is contained in:
parent
9767774147
commit
152856dfbc
@ -996,7 +996,7 @@ class TelegramClient(TelegramBareClient):
|
|||||||
|
|
||||||
# region Small utilities to make users' life easier
|
# region Small utilities to make users' life easier
|
||||||
|
|
||||||
def get_entity(self, entity):
|
def get_entity(self, entity, force_fetch=False):
|
||||||
"""
|
"""
|
||||||
Turns the given entity into a valid Telegram user or chat.
|
Turns the given entity into a valid Telegram user or chat.
|
||||||
|
|
||||||
@ -1014,8 +1014,16 @@ class TelegramClient(TelegramBareClient):
|
|||||||
|
|
||||||
If the entity is neither, and it's not a TLObject, an
|
If the entity is neither, and it's not a TLObject, an
|
||||||
error will be raised.
|
error will be raised.
|
||||||
|
|
||||||
|
:param force_fetch:
|
||||||
|
If True, the entity cache is bypassed and the entity is fetched
|
||||||
|
again with an API call. Defaults to False to avoid unnecessary
|
||||||
|
calls, but since a cached version would be returned, the entity
|
||||||
|
may be out of date.
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if not force_fetch:
|
||||||
|
# Try to use cache unless we want to force a fetch
|
||||||
try:
|
try:
|
||||||
return self.session.entities[entity]
|
return self.session.entities[entity]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Loading…
Reference in New Issue
Block a user