diff --git a/readthedocs/extra/advanced-usage/mastering-telethon.rst b/readthedocs/extra/advanced-usage/mastering-telethon.rst index 05dd9340..a0270250 100644 --- a/readthedocs/extra/advanced-usage/mastering-telethon.rst +++ b/readthedocs/extra/advanced-usage/mastering-telethon.rst @@ -262,7 +262,7 @@ You can also except it and act as you prefer: print('Flood waited for', e.seconds) quit(1) -VoIP numbers are very limited, and some countries are more limitted too. +VoIP numbers are very limited, and some countries are more limited too. Chat or User From Messages ************************** diff --git a/telethon/client/users.py b/telethon/client/users.py index 82d2c4ab..40b0e92a 100644 --- a/telethon/client/users.py +++ b/telethon/client/users.py @@ -401,6 +401,23 @@ class UserMethods(TelegramBaseClient): 'Cannot find any entity corresponding to "{}"'.format(string) ) + async def _get_input_dialog(self, dialog): + """ + Returns a :tl:`InputDialogPeer`. This is a bit tricky because + it may or not need access to the client to convert what's given + into an input entity. + """ + try: + if dialog.SUBCLASS_OF_ID == 0xa21c9795: # crc32(b'InputDialogPeer') + dialog.peer = await self.get_input_entity(dialog.peer) + return dialog + elif dialog.SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer') + return types.InputDialogPeer(dialog) + except AttributeError: + pass + + return types.InputDialogPeer(await self.get_input_entity(dialog)) + async def _get_input_notify(self, notify): """ Returns a :tl:`InputNotifyPeer`. This is a bit tricky because diff --git a/telethon_generator/generators/docs.py b/telethon_generator/generators/docs.py index ecfdee66..ea42ddaf 100755 --- a/telethon_generator/generators/docs.py +++ b/telethon_generator/generators/docs.py @@ -192,7 +192,8 @@ def _get_description(arg): 'None and can be omitted.') otherwise = True - if arg.type in {'InputPeer', 'InputUser', 'InputChannel'}: + if arg.type in {'InputPeer', 'InputUser', 'InputChannel', + 'InputNotifyPeer', 'InputDialogPeer'}: desc.append( 'Anything entity-like will work if the library can find its ' 'Input version (e.g., usernames, Peer, ' diff --git a/telethon_generator/generators/tlobject.py b/telethon_generator/generators/tlobject.py index 103c0177..ee31defb 100644 --- a/telethon_generator/generators/tlobject.py +++ b/telethon_generator/generators/tlobject.py @@ -20,9 +20,8 @@ AUTO_CASTS = { 'utils.get_input_channel(await client.get_input_entity({}))', 'InputUser': 'utils.get_input_user(await client.get_input_entity({}))', - 'InputDialogPeer': - 'utils.get_input_dialog(await client.get_input_entity({}))', + 'InputDialogPeer': 'await client._get_input_dialog({})', 'InputNotifyPeer': 'await client._get_input_notify({})', 'InputMedia': 'utils.get_input_media({})', 'InputPhoto': 'utils.get_input_photo({})',