mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +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))
|
||||
|
||||
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(
|
||||
entity, _tl.SendMessageCancelAction()))
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ class _MessagesIter(requestiter.RequestIter):
|
|||
# We want to skip the one we already have
|
||||
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,
|
||||
# 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
|
||||
|
@ -254,7 +254,7 @@ class _MessagesIter(requestiter.RequestIter):
|
|||
# getHistory, searchGlobal and getReplies call it offset_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:
|
||||
self.request.offset_peer = last_message.input_chat
|
||||
else:
|
||||
|
|
|
@ -197,7 +197,7 @@ def init(
|
|||
_tl.InputClientProxy(*connection.address_info(proxy))
|
||||
|
||||
# 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()
|
||||
|
||||
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.
|
||||
#
|
||||
# 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
|
||||
# set already. Avoid invoking non-CDN methods by not syncing updates.
|
||||
client.connect(_sync_updates=False)
|
||||
|
|
|
@ -173,7 +173,7 @@ class TelegramClient:
|
|||
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
|
||||
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
|
||||
requests are done as a takeout:
|
||||
|
||||
|
@ -764,7 +764,7 @@ class TelegramClient:
|
|||
This has no effect if a ``filter`` is given.
|
||||
|
||||
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
|
||||
matched :tl:`ChannelParticipant` type for channels/megagroups
|
||||
or :tl:`ChatParticipants` for normal chats.
|
||||
|
@ -2067,7 +2067,7 @@ class TelegramClient:
|
|||
|
||||
.. 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
|
||||
second is the default for this limit (or above).
|
||||
|
||||
|
@ -2125,7 +2125,7 @@ class TelegramClient:
|
|||
|
||||
wait_time (`int`):
|
||||
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
|
||||
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.
|
||||
pass
|
||||
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
|
||||
# ValueError("Request was unsuccessful N time(s)") for whatever reasons.
|
||||
pass
|
||||
|
|
|
@ -341,7 +341,7 @@ async def upload_file(
|
|||
# what Telegram wants.
|
||||
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)
|
||||
if is_big:
|
||||
request = _tl.fn.upload.SaveBigFilePart(
|
||||
|
|
|
@ -208,7 +208,7 @@ async def get_entity(
|
|||
chats = lists[helpers._EntityType.CHAT]
|
||||
channels = lists[helpers._EntityType.CHANNEL]
|
||||
if users:
|
||||
# GetUsersRequest has a limit of 200 per call
|
||||
# GetUsers has a limit of 200 per call
|
||||
tmp = []
|
||||
while users:
|
||||
curr, users = users[:200], users[200:]
|
||||
|
|
|
@ -74,7 +74,7 @@ class CdnDecrypter:
|
|||
|
||||
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.
|
||||
|
||||
:return: the CdnFile result.
|
||||
|
|
|
@ -102,7 +102,7 @@ class MTProtoState:
|
|||
# The `RequestState` stores `bytes(request)`, not the request itself.
|
||||
# `invokeAfterMsg` wants a `TLRequest` though, hence the wrapping.
|
||||
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(body)
|
||||
|
|
|
@ -242,7 +242,7 @@ class CallbackQuery(EventBuilder):
|
|||
|
||||
self._answered = True
|
||||
return await self._client(
|
||||
_tl.fn.messages.SetBotCallbackAnswerRequest(
|
||||
_tl.fn.messages.SetBotCallbackAnswer(
|
||||
query_id=self.query.query_id,
|
||||
cache_time=cache_time,
|
||||
alert=alert,
|
||||
|
|
|
@ -132,7 +132,7 @@ class Draft:
|
|||
raw_text, entities =\
|
||||
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,
|
||||
message=raw_text,
|
||||
no_webpage=not link_preview,
|
||||
|
|
|
@ -72,7 +72,7 @@ class MessageButton:
|
|||
it will be "clicked" and the :tl:`BotCallbackAnswer` returned.
|
||||
|
||||
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.
|
||||
|
||||
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 logging
|
||||
|
@ -44,13 +44,13 @@ bot = TelegramClient(
|
|||
|
||||
|
||||
# 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.
|
||||
@bot.on(events.Raw(types.UpdateBotPrecheckoutQuery))
|
||||
async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
||||
# If we don't `SetBotPrecheckoutResults`, money won't be charged from buyer, and nothing will happen next.
|
||||
@bot.on(events.Raw(_tl.UpdateBotPrecheckoutQuery))
|
||||
async def payment_pre_checkout_handler(event: _tl.UpdateBotPrecheckoutQuery):
|
||||
if event.payload.decode('UTF-8') == 'product A':
|
||||
# so we have to confirm payment
|
||||
await bot(
|
||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
||||
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||
query_id=event.query_id,
|
||||
success=True,
|
||||
error=None
|
||||
|
@ -59,7 +59,7 @@ async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
|||
elif event.payload.decode('UTF-8') == 'product B':
|
||||
# same for another
|
||||
await bot(
|
||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
||||
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||
query_id=event.query_id,
|
||||
success=True,
|
||||
error=None
|
||||
|
@ -68,7 +68,7 @@ async def payment_pre_checkout_handler(event: types.UpdateBotPrecheckoutQuery):
|
|||
else:
|
||||
# for example, something went wrong (whatever reason). We can tell customer about that:
|
||||
await bot(
|
||||
functions.messages.SetBotPrecheckoutResultsRequest(
|
||||
_tl.fn.messages.SetBotPrecheckoutResults(
|
||||
query_id=event.query_id,
|
||||
success=False,
|
||||
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.
|
||||
@bot.on(events.Raw(types.UpdateNewMessage))
|
||||
@bot.on(events.Raw(_tl.UpdateNewMessage))
|
||||
async def payment_received_handler(event):
|
||||
if isinstance(event.message.action, types.MessageActionPaymentSentMe):
|
||||
payment: types.MessageActionPaymentSentMe = event.message.action
|
||||
if isinstance(event.message.action, _tl.MessageActionPaymentSentMe):
|
||||
payment: _tl.MessageActionPaymentSentMe = event.message.action
|
||||
# do something after payment was received
|
||||
if payment.payload.decode('UTF-8') == '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
|
||||
def generate_invoice(price_label: str, price_amount: int, currency: str, title: str,
|
||||
description: str, payload: str, start_param: str) -> types.InputMediaInvoice:
|
||||
price = types.LabeledPrice(label=price_label, amount=price_amount) # label - just a text, amount=10000 means 100.00
|
||||
invoice = types.Invoice(
|
||||
description: str, payload: str, start_param: str) -> _tl.InputMediaInvoice:
|
||||
price = _tl.LabeledPrice(label=price_label, amount=price_amount) # label - just a text, amount=10000 means 100.00
|
||||
invoice = _tl.Invoice(
|
||||
currency=currency, # currency like USD
|
||||
prices=[price], # there could be a couple of prices.
|
||||
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,
|
||||
email_to_provider=False
|
||||
)
|
||||
return types.InputMediaInvoice(
|
||||
return _tl.InputMediaInvoice(
|
||||
title=title,
|
||||
description=description,
|
||||
invoice=invoice,
|
||||
payload=payload.encode('UTF-8'), # payload, which will be sent to next 2 handlers
|
||||
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
|
||||
# required fields should be provided by the payment provider.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user