diff --git a/telethon_generator/tl_generator.py b/telethon_generator/tl_generator.py index 5ccaa27c..cffb0f75 100755 --- a/telethon_generator/tl_generator.py +++ b/telethon_generator/tl_generator.py @@ -186,6 +186,12 @@ class TLGenerator: builder.writeln('from {}.tl.mtproto_request import MTProtoRequest' .format('.' * depth)) + if any(a for a in tlobject.args if a.type == 'InputPeer'): + # We can automatically convert a normal peer to an InputPeer, + # it will make invoking a lot of requests a lot simpler. + builder.writeln('from {}.utils import get_input_peer' + .format('.' * depth)) + if any(a for a in tlobject.args if a.can_be_inferred): # Currently only 'random_id' needs 'os' to be imported builder.writeln('import os') @@ -306,6 +312,10 @@ class TLGenerator: ) else: raise ValueError('Cannot infer a value for ', arg) + elif arg.type == 'InputPeer': + # Well-known case, auto-cast it to the right type + builder.writeln( + 'self.{0} = get_input_peer({0})'.format(arg.name)) else: builder.writeln('self.{0} = {0}'.format(arg.name))