mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-12-01 13:53:45 +03:00
Address remaining uses of the Request suffix with raw API
This commit is contained in:
parent
eb659b9a58
commit
943ad892f7
|
@ -524,7 +524,7 @@ def action(
|
||||||
raise ValueError('Cannot use {} as action'.format(action))
|
raise ValueError('Cannot use {} as action'.format(action))
|
||||||
|
|
||||||
if isinstance(action, _tl.SendMessageCancelAction):
|
if isinstance(action, _tl.SendMessageCancelAction):
|
||||||
# ``SetTypingRequest.resolve`` will get input peer of ``entity``.
|
# ``SetTyping.resolve`` will get input peer of ``entity``.
|
||||||
return self(_tl.fn.messages.SetTyping(
|
return self(_tl.fn.messages.SetTyping(
|
||||||
entity, _tl.SendMessageCancelAction()))
|
entity, _tl.SendMessageCancelAction()))
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ class _MessagesIter(requestiter.RequestIter):
|
||||||
# We want to skip the one we already have
|
# We want to skip the one we already have
|
||||||
self.request.offset_id += 1
|
self.request.offset_id += 1
|
||||||
|
|
||||||
if isinstance(self.request, _tl.fn.messages.SearchRequest):
|
if isinstance(self.request, _tl.fn.messages.Search):
|
||||||
# Unlike getHistory and searchGlobal that use *offset* date,
|
# Unlike getHistory and searchGlobal that use *offset* date,
|
||||||
# this is *max* date. This means that doing a search in reverse
|
# this is *max* date. This means that doing a search in reverse
|
||||||
# will break it. Since it's not really needed once we're going
|
# will break it. Since it's not really needed once we're going
|
||||||
|
@ -254,7 +254,7 @@ class _MessagesIter(requestiter.RequestIter):
|
||||||
# getHistory, searchGlobal and getReplies call it offset_date
|
# getHistory, searchGlobal and getReplies call it offset_date
|
||||||
self.request.offset_date = last_message.date
|
self.request.offset_date = last_message.date
|
||||||
|
|
||||||
if isinstance(self.request, _tl.fn.messages.SearchGlobalRequest):
|
if isinstance(self.request, _tl.fn.messages.SearchGlobal):
|
||||||
if last_message.input_chat:
|
if last_message.input_chat:
|
||||||
self.request.offset_peer = last_message.input_chat
|
self.request.offset_peer = last_message.input_chat
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -197,7 +197,7 @@ def init(
|
||||||
_tl.InputClientProxy(*connection.address_info(proxy))
|
_tl.InputClientProxy(*connection.address_info(proxy))
|
||||||
|
|
||||||
# Used on connection. Capture the variables in a lambda since
|
# Used on connection. Capture the variables in a lambda since
|
||||||
# exporting clients need to create this InvokeWithLayerRequest.
|
# exporting clients need to create this InvokeWithLayer.
|
||||||
system = platform.uname()
|
system = platform.uname()
|
||||||
|
|
||||||
if system.machine in ('x86_64', 'AMD64'):
|
if system.machine in ('x86_64', 'AMD64'):
|
||||||
|
@ -559,7 +559,7 @@ async def _get_cdn_client(self: 'TelegramClient', cdn_redirect):
|
||||||
|
|
||||||
# This will make use of the new RSA keys for this specific CDN.
|
# This will make use of the new RSA keys for this specific CDN.
|
||||||
#
|
#
|
||||||
# We won't be calling GetConfigRequest because it's only called
|
# We won't be calling GetConfig because it's only called
|
||||||
# when needed by ._get_dc, and also it's static so it's likely
|
# when needed by ._get_dc, and also it's static so it's likely
|
||||||
# set already. Avoid invoking non-CDN methods by not syncing updates.
|
# set already. Avoid invoking non-CDN methods by not syncing updates.
|
||||||
client.connect(_sync_updates=False)
|
client.connect(_sync_updates=False)
|
||||||
|
|
|
@ -173,7 +173,7 @@ class TelegramClient:
|
||||||
Returns a :ref:`telethon-client` which calls methods behind a takeout session.
|
Returns a :ref:`telethon-client` which calls methods behind a takeout session.
|
||||||
|
|
||||||
It does so by creating a proxy object over the current client through
|
It does so by creating a proxy object over the current client through
|
||||||
which making requests will use :tl:`InvokeWithTakeoutRequest` to wrap
|
which making requests will use :tl:`InvokeWithTakeout` to wrap
|
||||||
them. In other words, returns the current client modified so that
|
them. In other words, returns the current client modified so that
|
||||||
requests are done as a takeout:
|
requests are done as a takeout:
|
||||||
|
|
||||||
|
@ -764,7 +764,7 @@ class TelegramClient:
|
||||||
This has no effect if a ``filter`` is given.
|
This has no effect if a ``filter`` is given.
|
||||||
|
|
||||||
Yields
|
Yields
|
||||||
The :tl:`User` objects returned by :tl:`GetParticipantsRequest`
|
The :tl:`User` objects returned by :tl:`GetParticipants`
|
||||||
with an additional ``.participant`` attribute which is the
|
with an additional ``.participant`` attribute which is the
|
||||||
matched :tl:`ChannelParticipant` type for channels/megagroups
|
matched :tl:`ChannelParticipant` type for channels/megagroups
|
||||||
or :tl:`ChatParticipants` for normal chats.
|
or :tl:`ChatParticipants` for normal chats.
|
||||||
|
@ -2067,7 +2067,7 @@ class TelegramClient:
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Telegram's flood wait limit for :tl:`GetHistoryRequest` seems to
|
Telegram's flood wait limit for :tl:`GetHistory` seems to
|
||||||
be around 30 seconds per 10 requests, therefore a sleep of 1
|
be around 30 seconds per 10 requests, therefore a sleep of 1
|
||||||
second is the default for this limit (or above).
|
second is the default for this limit (or above).
|
||||||
|
|
||||||
|
@ -2125,7 +2125,7 @@ class TelegramClient:
|
||||||
|
|
||||||
wait_time (`int`):
|
wait_time (`int`):
|
||||||
Wait time (in seconds) between different
|
Wait time (in seconds) between different
|
||||||
:tl:`GetHistoryRequest`. Use this parameter to avoid hitting
|
:tl:`GetHistory`. Use this parameter to avoid hitting
|
||||||
the ``FloodWaitError`` as needed. If left to `None`, it will
|
the ``FloodWaitError`` as needed. If left to `None`, it will
|
||||||
default to 1 second only if the limit is higher than 3000.
|
default to 1 second only if the limit is higher than 3000.
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,7 @@ async def _dispatch_update(self: 'TelegramClient', update, others, channel_id, p
|
||||||
# we should be okay (no flood waits) even if more occur.
|
# we should be okay (no flood waits) even if more occur.
|
||||||
pass
|
pass
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# There is a chance that GetFullChannelRequest and GetDifferenceRequest
|
# There is a chance that GetFullChannel and GetDifference
|
||||||
# inside the _get_difference() function will end up with
|
# inside the _get_difference() function will end up with
|
||||||
# ValueError("Request was unsuccessful N time(s)") for whatever reasons.
|
# ValueError("Request was unsuccessful N time(s)") for whatever reasons.
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -341,7 +341,7 @@ async def upload_file(
|
||||||
# what Telegram wants.
|
# what Telegram wants.
|
||||||
hash_md5.update(part)
|
hash_md5.update(part)
|
||||||
|
|
||||||
# The SavePartRequest is different depending on whether
|
# The SavePart is different depending on whether
|
||||||
# the file is too large or not (over or less than 10MB)
|
# the file is too large or not (over or less than 10MB)
|
||||||
if is_big:
|
if is_big:
|
||||||
request = _tl.fn.upload.SaveBigFilePart(
|
request = _tl.fn.upload.SaveBigFilePart(
|
||||||
|
|
|
@ -208,7 +208,7 @@ async def get_entity(
|
||||||
chats = lists[helpers._EntityType.CHAT]
|
chats = lists[helpers._EntityType.CHAT]
|
||||||
channels = lists[helpers._EntityType.CHANNEL]
|
channels = lists[helpers._EntityType.CHANNEL]
|
||||||
if users:
|
if users:
|
||||||
# GetUsersRequest has a limit of 200 per call
|
# GetUsers has a limit of 200 per call
|
||||||
tmp = []
|
tmp = []
|
||||||
while users:
|
while users:
|
||||||
curr, users = users[:200], users[200:]
|
curr, users = users[:200], users[200:]
|
||||||
|
|
|
@ -74,7 +74,7 @@ class CdnDecrypter:
|
||||||
|
|
||||||
def get_file(self):
|
def get_file(self):
|
||||||
"""
|
"""
|
||||||
Calls GetCdnFileRequest and decrypts its bytes.
|
Calls GetCdnFile and decrypts its bytes.
|
||||||
Also ensures that the file hasn't been tampered.
|
Also ensures that the file hasn't been tampered.
|
||||||
|
|
||||||
:return: the CdnFile result.
|
:return: the CdnFile result.
|
||||||
|
|
|
@ -102,7 +102,7 @@ class MTProtoState:
|
||||||
# The `RequestState` stores `bytes(request)`, not the request itself.
|
# The `RequestState` stores `bytes(request)`, not the request itself.
|
||||||
# `invokeAfterMsg` wants a `TLRequest` though, hence the wrapping.
|
# `invokeAfterMsg` wants a `TLRequest` though, hence the wrapping.
|
||||||
body = GzipPacked.gzip_if_smaller(content_related,
|
body = GzipPacked.gzip_if_smaller(content_related,
|
||||||
bytes(_tl.fn.InvokeAfterMsgRequest(after_id, _OpaqueRequest(data))))
|
bytes(_tl.fn.InvokeAfterMsg(after_id, _OpaqueRequest(data))))
|
||||||
|
|
||||||
buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
|
buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
|
||||||
buffer.write(body)
|
buffer.write(body)
|
||||||
|
|
|
@ -242,7 +242,7 @@ class CallbackQuery(EventBuilder):
|
||||||
|
|
||||||
self._answered = True
|
self._answered = True
|
||||||
return await self._client(
|
return await self._client(
|
||||||
_tl.fn.messages.SetBotCallbackAnswerRequest(
|
_tl.fn.messages.SetBotCallbackAnswer(
|
||||||
query_id=self.query.query_id,
|
query_id=self.query.query_id,
|
||||||
cache_time=cache_time,
|
cache_time=cache_time,
|
||||||
alert=alert,
|
alert=alert,
|
||||||
|
|
|
@ -132,7 +132,7 @@ class Draft:
|
||||||
raw_text, entities =\
|
raw_text, entities =\
|
||||||
await self._client._parse_message_text(text, parse_mode)
|
await self._client._parse_message_text(text, parse_mode)
|
||||||
|
|
||||||
result = await self._client(_tl.fn.SaveDraftRequest(
|
result = await self._client(_tl.fn.SaveDraft(
|
||||||
peer=self._peer,
|
peer=self._peer,
|
||||||
message=raw_text,
|
message=raw_text,
|
||||||
no_webpage=not link_preview,
|
no_webpage=not link_preview,
|
||||||
|
|
|
@ -72,7 +72,7 @@ class MessageButton:
|
||||||
it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
|
it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
|
||||||
|
|
||||||
If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
|
If it's an inline :tl:`KeyboardButtonSwitchInline` button, the
|
||||||
:tl:`StartBotRequest` will be invoked and the resulting updates
|
:tl:`StartBot` will be invoked and the resulting updates
|
||||||
returned.
|
returned.
|
||||||
|
|
||||||
If it's a :tl:`KeyboardButtonUrl`, the URL of the button will
|
If it's a :tl:`KeyboardButtonUrl`, the URL of the button will
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from telethon import TelegramClient, events, types, functions
|
from telethon import TelegramClient, events, _tl
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
@ -44,13 +44,13 @@ bot = TelegramClient(
|
||||||
|
|
||||||
|
|
||||||
# That event is handled when customer enters his card/etc, on final pre-checkout
|
# That event is handled when customer enters his card/etc, on final pre-checkout
|
||||||
# If we don't `SetBotPrecheckoutResultsRequest`, money won't be charged from buyer, and nothing will happen next.
|
# If we don't `SetBotPrecheckoutResults`, money won't be charged from buyer, and nothing will happen next.
|
||||||
@bot.on(events.Raw(types.UpdateBotPrecheckoutQuery))
|
@bot.on(events.Raw(_tl.UpdateBotPrecheckoutQuery))
|
||||||
async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
async def payment_pre_checkout_handler(event: _tl.UpdateBotPrecheckoutQuery):
|
||||||
if event.payload.decode('UTF-8') == 'product A':
|
if event.payload.decode('UTF-8') == 'product A':
|
||||||
# so we have to confirm payment
|
# so we have to confirm payment
|
||||||
await bot(
|
await bot(
|
||||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||||
query_id=event.query_id,
|
query_id=event.query_id,
|
||||||
success=True,
|
success=True,
|
||||||
error=None
|
error=None
|
||||||
|
@ -59,7 +59,7 @@ async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
||||||
elif event.payload.decode('UTF-8') == 'product B':
|
elif event.payload.decode('UTF-8') == 'product B':
|
||||||
# same for another
|
# same for another
|
||||||
await bot(
|
await bot(
|
||||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||||
query_id=event.query_id,
|
query_id=event.query_id,
|
||||||
success=True,
|
success=True,
|
||||||
error=None
|
error=None
|
||||||
|
@ -68,7 +68,7 @@ async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
||||||
else:
|
else:
|
||||||
# for example, something went wrong (whatever reason). We can tell customer about that:
|
# for example, something went wrong (whatever reason). We can tell customer about that:
|
||||||
await bot(
|
await bot(
|
||||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||||
query_id=event.query_id,
|
query_id=event.query_id,
|
||||||
success=False,
|
success=False,
|
||||||
error='Something went wrong'
|
error='Something went wrong'
|
||||||
|
@ -79,10 +79,10 @@ async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
||||||
|
|
||||||
|
|
||||||
# That event is handled at the end, when customer payed.
|
# That event is handled at the end, when customer payed.
|
||||||
@bot.on(events.Raw(types.UpdateNewMessage))
|
@bot.on(events.Raw(_tl.UpdateNewMessage))
|
||||||
async def payment_received_handler(event):
|
async def payment_received_handler(event):
|
||||||
if isinstance(event.message.action, types.MessageActionPaymentSentMe):
|
if isinstance(event.message.action, _tl.MessageActionPaymentSentMe):
|
||||||
payment: types.MessageActionPaymentSentMe = event.message.action
|
payment: _tl.MessageActionPaymentSentMe = event.message.action
|
||||||
# do something after payment was received
|
# do something after payment was received
|
||||||
if payment.payload.decode('UTF-8') == 'product A':
|
if payment.payload.decode('UTF-8') == 'product A':
|
||||||
await bot.send_message(event.message.from_id, 'Thank you for buying product A!')
|
await bot.send_message(event.message.from_id, 'Thank you for buying product A!')
|
||||||
|
@ -93,9 +93,9 @@ async def payment_received_handler(event):
|
||||||
|
|
||||||
# let's put it in one function for more easier way
|
# let's put it in one function for more easier way
|
||||||
def generate_invoice(price_label: str, price_amount: int, currency: str, title: str,
|
def generate_invoice(price_label: str, price_amount: int, currency: str, title: str,
|
||||||
description: str, payload: str, start_param: str) -> types.InputMediaInvoice:
|
description: str, payload: str, start_param: str) -> _tl.InputMediaInvoice:
|
||||||
price = types.LabeledPrice(label=price_label, amount=price_amount) # label - just a text, amount=10000 means 100.00
|
price = _tl.LabeledPrice(label=price_label, amount=price_amount) # label - just a text, amount=10000 means 100.00
|
||||||
invoice = types.Invoice(
|
invoice = _tl.Invoice(
|
||||||
currency=currency, # currency like USD
|
currency=currency, # currency like USD
|
||||||
prices=[price], # there could be a couple of prices.
|
prices=[price], # there could be a couple of prices.
|
||||||
test=True, # if you're working with test token, else set test=False.
|
test=True, # if you're working with test token, else set test=False.
|
||||||
|
@ -114,14 +114,14 @@ def generate_invoice(price_label: str, price_amount: int, currency: str, title:
|
||||||
phone_to_provider=False,
|
phone_to_provider=False,
|
||||||
email_to_provider=False
|
email_to_provider=False
|
||||||
)
|
)
|
||||||
return types.InputMediaInvoice(
|
return _tl.InputMediaInvoice(
|
||||||
title=title,
|
title=title,
|
||||||
description=description,
|
description=description,
|
||||||
invoice=invoice,
|
invoice=invoice,
|
||||||
payload=payload.encode('UTF-8'), # payload, which will be sent to next 2 handlers
|
payload=payload.encode('UTF-8'), # payload, which will be sent to next 2 handlers
|
||||||
provider=provider_token,
|
provider=provider_token,
|
||||||
|
|
||||||
provider_data=types.DataJSON('{}'),
|
provider_data=_tl.DataJSON('{}'),
|
||||||
# data about the invoice, which will be shared with the payment provider. A detailed description of
|
# data about the invoice, which will be shared with the payment provider. A detailed description of
|
||||||
# required fields should be provided by the payment provider.
|
# required fields should be provided by the payment provider.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user