mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Automatically call .get_input_peer on the requests that need it
This commit is contained in:
parent
c02fbae5aa
commit
b8e46446ba
|
@ -186,6 +186,12 @@ class TLGenerator:
|
||||||
builder.writeln('from {}.tl.mtproto_request import MTProtoRequest'
|
builder.writeln('from {}.tl.mtproto_request import MTProtoRequest'
|
||||||
.format('.' * depth))
|
.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):
|
if any(a for a in tlobject.args if a.can_be_inferred):
|
||||||
# Currently only 'random_id' needs 'os' to be imported
|
# Currently only 'random_id' needs 'os' to be imported
|
||||||
builder.writeln('import os')
|
builder.writeln('import os')
|
||||||
|
@ -306,6 +312,10 @@ class TLGenerator:
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Cannot infer a value for ', arg)
|
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:
|
else:
|
||||||
builder.writeln('self.{0} = {0}'.format(arg.name))
|
builder.writeln('self.{0} = {0}'.format(arg.name))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user