2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Rename Client.send to Client.invoke

This commit is contained in:
Dan 2022-04-24 11:56:07 +02:00
parent 4f6ce8bec1
commit 78efb04b40
144 changed files with 234 additions and 236 deletions

View File

@ -567,7 +567,7 @@ class Client(Methods):
if not isinstance(message, raw.types.MessageEmpty):
try:
diff = await self.send(
diff = await self.invoke(
raw.functions.updates.GetChannelDifference(
channel=await self.resolve_peer(utils.get_channel_id(channel_id)),
filter=raw.types.ChannelMessagesFilter(
@ -589,7 +589,7 @@ class Client(Methods):
self.dispatcher.updates_queue.put_nowait((update, users, chats))
elif isinstance(updates, (raw.types.UpdateShortMessage, raw.types.UpdateShortChatMessage)):
diff = await self.send(
diff = await self.invoke(
raw.functions.updates.GetDifference(
pts=updates.pts - updates.pts_count,
date=updates.date,
@ -847,14 +847,14 @@ class Client(Methods):
await session.start()
for _ in range(3):
exported_auth = await self.send(
exported_auth = await self.invoke(
raw.functions.auth.ExportAuthorization(
dc_id=dc_id
)
)
try:
await session.send(
await session.invoke(
raw.functions.auth.ImportAuthorization(
id=exported_auth.id,
bytes=exported_auth.bytes
@ -920,7 +920,7 @@ class Client(Methods):
file_name = ""
try:
r = await session.send(
r = await session.invoke(
raw.functions.upload.GetFile(
location=location,
offset=offset,
@ -958,7 +958,7 @@ class Client(Methods):
if len(chunk) < limit:
break
r = await session.send(
r = await session.invoke(
raw.functions.upload.GetFile(
location=location,
offset=offset,
@ -986,7 +986,7 @@ class Client(Methods):
file_name = f.name
while True:
r2 = await cdn_session.send(
r2 = await cdn_session.invoke(
raw.functions.upload.GetCdnFile(
file_token=r.file_token,
offset=offset,
@ -996,7 +996,7 @@ class Client(Methods):
if isinstance(r2, raw.types.upload.CdnFileReuploadNeeded):
try:
await session.send(
await session.invoke(
raw.functions.upload.ReuploadCdnFile(
file_token=r.file_token,
request_token=r2.request_token
@ -1019,7 +1019,7 @@ class Client(Methods):
)
)
hashes = await session.send(
hashes = await session.invoke(
raw.functions.upload.GetCdnFileHashes(
file_token=r.file_token,
offset=offset

View File

@ -16,14 +16,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .invoke import Invoke
from .resolve_peer import ResolvePeer
from .save_file import SaveFile
from .send import Send
class Advanced(
Invoke,
ResolvePeer,
SaveFile,
Send
SaveFile
):
pass

View File

@ -26,15 +26,15 @@ from pyrogram.session import Session
log = logging.getLogger(__name__)
class Send:
async def send(
class Invoke:
async def invoke(
self: "pyrogram.Client",
data: TLObject,
query: TLObject,
retries: int = Session.MAX_RETRIES,
timeout: float = Session.WAIT_TIMEOUT,
sleep_threshold: float = None
):
"""Send raw Telegram queries.
"""Invoke raw Telegram functions.
This method makes it possible to manually call every single Telegram API method in a low-level manner.
Available functions are listed in the :obj:`functions <pyrogram.api.functions>` package and may accept compound
@ -47,7 +47,7 @@ class Send:
available yet in the Client class as an easy-to-use method).
Parameters:
data (``RawFunction``):
query (``RawFunction``):
The API Schema function filled with proper arguments.
retries (``int``):
@ -69,13 +69,13 @@ class Send:
raise ConnectionError("Client has not been started yet")
if self.no_updates:
data = raw.functions.InvokeWithoutUpdates(query=data)
query = raw.functions.InvokeWithoutUpdates(query=query)
if self.takeout_id:
data = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=data)
query = raw.functions.InvokeWithTakeout(takeout_id=self.takeout_id, query=query)
r = await self.session.send(
data, retries, timeout,
r = await self.session.invoke(
query, retries, timeout,
(sleep_threshold
if sleep_threshold is not None
else self.sleep_threshold)

View File

@ -71,7 +71,7 @@ class ResolvePeer:
try:
return await self.storage.get_peer_by_username(peer_id)
except KeyError:
await self.send(
await self.invoke(
raw.functions.contacts.ResolveUsername(
username=peer_id
)
@ -88,7 +88,7 @@ class ResolvePeer:
if peer_type == "user":
await self.fetch_peers(
await self.send(
await self.invoke(
raw.functions.users.GetUsers(
id=[
raw.types.InputUser(
@ -100,13 +100,13 @@ class ResolvePeer:
)
)
elif peer_type == "chat":
await self.send(
await self.invoke(
raw.functions.messages.GetChats(
id=[-peer_id]
)
)
else:
await self.send(
await self.invoke(
raw.functions.channels.GetChannels(
id=[
raw.types.InputChannel(

View File

@ -103,7 +103,7 @@ class SaveFile:
return
try:
await session.send(data)
await session.invoke(data)
except Exception as e:
log.error(e)

View File

@ -31,7 +31,7 @@ class AcceptTermsOfService:
terms_of_service_id (``str``):
The terms of service identifier.
"""
r = await self.send(
r = await self.invoke(
raw.functions.help.AcceptTermsOfService(
id=raw.types.DataJSON(
data=terms_of_service_id

View File

@ -43,10 +43,10 @@ class CheckPassword:
Raises:
BadRequest: In case the password is invalid.
"""
r = await self.send(
r = await self.invoke(
raw.functions.auth.CheckPassword(
password=compute_password_check(
await self.send(raw.functions.account.GetPassword()),
await self.invoke(raw.functions.account.GetPassword()),
password
)
)

View File

@ -33,4 +33,4 @@ class GetPasswordHint:
Returns:
``str``: On success, the password hint as string is returned.
"""
return (await self.send(raw.functions.account.GetPassword())).hint
return (await self.invoke(raw.functions.account.GetPassword())).hint

View File

@ -42,7 +42,7 @@ class LogOut:
# Log out.
app.log_out()
"""
await self.send(raw.functions.auth.LogOut())
await self.invoke(raw.functions.auth.LogOut())
await self.stop()
await self.storage.delete()

View File

@ -43,7 +43,7 @@ class RecoverPassword:
Raises:
BadRequest: In case the recovery code is invalid.
"""
r = await self.send(
r = await self.invoke(
raw.functions.auth.RecoverPassword(
code=recovery_code
)

View File

@ -52,7 +52,7 @@ class ResendCode:
"""
phone_number = phone_number.strip(" +")
r = await self.send(
r = await self.invoke(
raw.functions.auth.ResendCode(
phone_number=phone_number,
phone_code_hash=phone_code_hash

View File

@ -49,7 +49,7 @@ class SendCode:
while True:
try:
r = await self.send(
r = await self.invoke(
raw.functions.auth.SendCode(
phone_number=phone_number,
api_id=self.api_id,

View File

@ -36,6 +36,6 @@ class SendRecoveryCode:
Raises:
BadRequest: In case no recovery email was set up.
"""
return (await self.send(
return (await self.invoke(
raw.functions.auth.RequestPasswordRecovery()
)).email_pattern

View File

@ -58,7 +58,7 @@ class SignIn:
"""
phone_number = phone_number.strip(" +")
r = await self.send(
r = await self.invoke(
raw.functions.auth.SignIn(
phone_number=phone_number,
phone_code_hash=phone_code_hash,

View File

@ -46,7 +46,7 @@ class SignInBot:
"""
while True:
try:
r = await self.send(
r = await self.invoke(
raw.functions.auth.ImportBotAuthorization(
flags=0,
api_id=self.api_id,

View File

@ -56,7 +56,7 @@ class SignUp:
"""
phone_number = phone_number.strip(" +")
r = await self.send(
r = await self.invoke(
raw.functions.auth.SignUp(
phone_number=phone_number,
first_name=first_name,

View File

@ -41,7 +41,7 @@ class Terminate:
raise ConnectionError("Client is already terminated")
if self.takeout_id:
await self.send(raw.functions.account.FinishTakeoutSession())
await self.invoke(raw.functions.account.FinishTakeoutSession())
log.warning(f"Takeout session {self.takeout_id} finished")
await Syncer.remove(self)

View File

@ -68,7 +68,7 @@ class AnswerCallbackQuery:
# Answer with alert
app.answer_callback_query(query_id, text=text, show_alert=True)
"""
return await self.send(
return await self.invoke(
raw.functions.messages.SetBotCallbackAnswer(
query_id=int(callback_query_id),
cache_time=cache_time,

View File

@ -94,7 +94,7 @@ class AnswerInlineQuery:
InputTextMessageContent("Message content"))])
"""
return await self.send(
return await self.invoke(
raw.functions.messages.SetInlineBotResults(
query_id=int(inline_query_id),
results=[await r.write(self) for r in results],

View File

@ -59,7 +59,7 @@ class GetGameHighScores:
"""
# TODO: inline_message_id
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetGameHighScores(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -70,7 +70,7 @@ class GetInlineBotResults:
# TODO: Don't return the raw type
try:
return await self.send(
return await self.invoke(
raw.functions.messages.GetInlineBotResults(
bot=await self.resolve_peer(bot),
peer=raw.types.InputPeerSelf(),

View File

@ -64,7 +64,7 @@ class RequestCallbackAnswer:
# Telegram only wants bytes, but we are allowed to pass strings too.
data = bytes(callback_data, "utf-8") if isinstance(callback_data, str) else callback_data
return await self.send(
return await self.invoke(
raw.functions.messages.GetBotCallbackAnswer(
peer=await self.resolve_peer(chat_id),
msg_id=message_id,

View File

@ -71,7 +71,7 @@ class SendGame:
app.send_game(chat_id, "gamename")
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.SendMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaGame(

View File

@ -61,7 +61,7 @@ class SendInlineBotResult:
app.send_inline_bot_result(chat_id, query_id, result_id)
"""
return await self.send(
return await self.invoke(
raw.functions.messages.SendInlineBotResult(
peer=await self.resolve_peer(chat_id),
query_id=query_id,

View File

@ -62,7 +62,7 @@ class SetBotCommands:
BotCommand("settings", "Bot settings")])
"""
return await self.send(
return await self.invoke(
raw.functions.bots.SetBotCommands(
commands=[c.write() for c in commands],
scope=await scope.write(self),

View File

@ -75,7 +75,7 @@ class SetGameScore:
# Force set new score
app.set_game_score(user_id, 25, force=True)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.SetGameScore(
peer=await self.resolve_peer(chat_id),
score=score,

View File

@ -67,7 +67,7 @@ class AddChatMembers:
if isinstance(peer, raw.types.InputPeerChat):
for user_id in user_ids:
await self.send(
await self.invoke(
raw.functions.messages.AddChatUser(
chat_id=peer.chat_id,
user_id=await self.resolve_peer(user_id),
@ -75,7 +75,7 @@ class AddChatMembers:
)
)
else:
await self.send(
await self.invoke(
raw.functions.channels.InviteToChannel(
channel=peer,
users=[

View File

@ -60,7 +60,7 @@ class ArchiveChats:
)
)
await self.send(
await self.invoke(
raw.functions.folders.EditPeerFolders(
folder_peers=folder_peers
)

View File

@ -73,7 +73,7 @@ class BanChatMember:
user_peer = await self.resolve_peer(user_id)
if isinstance(chat_peer, raw.types.InputPeerChannel):
r = await self.send(
r = await self.invoke(
raw.functions.channels.EditBanned(
channel=chat_peer,
participant=user_peer,
@ -91,7 +91,7 @@ class BanChatMember:
)
)
else:
r = await self.send(
r = await self.invoke(
raw.functions.messages.DeleteChatUser(
chat_id=abs(chat_id),
user_id=user_peer

View File

@ -43,7 +43,7 @@ class CreateChannel:
app.create_channel("Channel Title", "Channel Description")
"""
r = await self.send(
r = await self.invoke(
raw.functions.channels.CreateChannel(
title=title,
about=description,

View File

@ -55,7 +55,7 @@ class CreateGroup:
if not isinstance(users, list):
users = [users]
r = await self.send(
r = await self.invoke(
raw.functions.messages.CreateChat(
title=title,
users=[await self.resolve_peer(u) for u in users]

View File

@ -47,7 +47,7 @@ class CreateSupergroup:
app.create_supergroup("Supergroup Title", "Supergroup Description")
"""
r = await self.send(
r = await self.invoke(
raw.functions.channels.CreateChannel(
title=title,
about=description,

View File

@ -41,7 +41,7 @@ class DeleteChannel:
app.delete_channel(channel_id)
"""
await self.send(
await self.invoke(
raw.functions.channels.DeleteChannel(
channel=await self.resolve_peer(chat_id)
)

View File

@ -49,14 +49,14 @@ class DeleteChatPhoto:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChat):
await self.send(
await self.invoke(
raw.functions.messages.EditChatPhoto(
chat_id=peer.chat_id,
photo=raw.types.InputChatPhotoEmpty()
)
)
elif isinstance(peer, raw.types.InputPeerChannel):
await self.send(
await self.invoke(
raw.functions.channels.EditPhoto(
channel=peer,
photo=raw.types.InputChatPhotoEmpty()

View File

@ -41,7 +41,7 @@ class DeleteSupergroup:
app.delete_supergroup(supergroup_id)
"""
await self.send(
await self.invoke(
raw.functions.channels.DeleteChannel(
channel=await self.resolve_peer(chat_id)
)

View File

@ -41,7 +41,7 @@ class DeleteUserHistory:
``bool``: True on success, False otherwise.
"""
r = await self.send(
r = await self.invoke(
raw.functions.channels.DeleteParticipantHistory(
channel=await self.resolve_peer(chat_id),
participant=await self.resolve_peer(user_id)

View File

@ -56,7 +56,7 @@ class GetChat:
match = self.INVITE_LINK_RE.match(str(chat_id))
if match:
r = await self.send(
r = await self.invoke(
raw.functions.messages.CheckChatInvite(
hash=match.group(1)
)
@ -76,10 +76,10 @@ class GetChat:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.send(raw.functions.channels.GetFullChannel(channel=peer))
r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.send(raw.functions.users.GetFullUser(id=peer))
r = await self.invoke(raw.functions.users.GetFullUser(id=peer))
else:
r = await self.send(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
return await types.Chat._parse_full(self, r)

View File

@ -70,7 +70,7 @@ class GetChatEventLog:
limit = min(100, total)
while True:
r: raw.base.channels.AdminLogResults = await self.send(
r: raw.base.channels.AdminLogResults = await self.invoke(
raw.functions.channels.GetAdminLog(
channel=await self.resolve_peer(chat_id),
q=query,

View File

@ -54,7 +54,7 @@ class GetChatMember:
user = await self.resolve_peer(user_id)
if isinstance(chat, raw.types.InputPeerChat):
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetFullChat(
chat_id=chat.chat_id
)
@ -75,7 +75,7 @@ class GetChatMember:
else:
raise UserNotParticipant
elif isinstance(chat, raw.types.InputPeerChannel):
r = await self.send(
r = await self.invoke(
raw.functions.channels.GetParticipant(
channel=chat,
participant=user

View File

@ -92,7 +92,7 @@ class GetChatMembers:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChat):
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetFullChat(
chat_id=peer.chat_id
)
@ -120,7 +120,7 @@ class GetChatMembers:
else:
raise ValueError(f'Invalid filter "{filter}"')
r = await self.send(
r = await self.invoke(
raw.functions.channels.GetParticipants(
channel=peer,
filter=filter,

View File

@ -48,7 +48,7 @@ class GetChatMembersCount:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChat):
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetChats(
id=[peer.chat_id]
)
@ -56,7 +56,7 @@ class GetChatMembersCount:
return r.chats[0].participants_count
elif isinstance(peer, raw.types.InputPeerChannel):
r = await self.send(
r = await self.invoke(
raw.functions.channels.GetFullChannel(
channel=peer
)

View File

@ -42,7 +42,7 @@ class GetChatOnlineCount:
online = app.get_chat_online_count(chat_id)
print(online)
"""
return (await self.send(
return (await self.invoke(
raw.functions.messages.GetOnlines(
peer=await self.resolve_peer(chat_id)
)

View File

@ -67,12 +67,12 @@ class GetDialogs:
"""
if pinned_only:
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetPinnedDialogs(folder_id=0),
sleep_threshold=60
)
else:
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetDialogs(
offset_date=utils.datetime_to_timestamp(offset_date),
offset_id=0,

View File

@ -42,9 +42,9 @@ class GetDialogsCount:
"""
if pinned_only:
return len((await self.send(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs)
return len((await self.invoke(raw.functions.messages.GetPinnedDialogs(folder_id=0))).dialogs)
else:
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetDialogs(
offset_date=0,
offset_id=0,

View File

@ -49,7 +49,7 @@ class GetNearbyChats:
print(chats)
"""
r = await self.send(
r = await self.invoke(
raw.functions.contacts.GetLocated(
geo_point=raw.types.InputGeoPoint(
lat=latitude,

View File

@ -43,7 +43,7 @@ class GetSendAsChats:
chats = app.get_send_as_chats(chat_id)
print(chats)
"""
r = await self.send(
r = await self.invoke(
raw.functions.channels.GetSendAs(
peer=await self.resolve_peer(chat_id)
)

View File

@ -57,7 +57,7 @@ class IterDialogs:
offset_peer = raw.types.InputPeerEmpty()
while True:
r = (await self.send(
r = (await self.invoke(
raw.functions.messages.GetDialogs(
offset_date=offset_date,
offset_id=offset_id,

View File

@ -53,7 +53,7 @@ class JoinChat:
match = self.INVITE_LINK_RE.match(str(chat_id))
if match:
chat = await self.send(
chat = await self.invoke(
raw.functions.messages.ImportChatInvite(
hash=match.group(1)
)
@ -63,7 +63,7 @@ class JoinChat:
elif isinstance(chat.chats[0], raw.types.Channel):
return types.Chat._parse_channel_chat(self, chat.chats[0])
else:
chat = await self.send(
chat = await self.invoke(
raw.functions.channels.JoinChannel(
channel=await self.resolve_peer(chat_id)
)

View File

@ -51,13 +51,13 @@ class LeaveChat:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChannel):
return await self.send(
return await self.invoke(
raw.functions.channels.LeaveChannel(
channel=await self.resolve_peer(chat_id)
)
)
elif isinstance(peer, raw.types.InputPeerChat):
r = await self.send(
r = await self.invoke(
raw.functions.messages.DeleteChatUser(
chat_id=peer.chat_id,
user_id=raw.types.InputUserSelf()
@ -65,7 +65,7 @@ class LeaveChat:
)
if delete:
await self.send(
await self.invoke(
raw.functions.messages.DeleteHistory(
peer=peer,
max_id=0

View File

@ -19,7 +19,7 @@
from typing import Union
import pyrogram
from pyrogram.raw import functions
from pyrogram import raw
class MarkChatUnread:
@ -37,8 +37,8 @@ class MarkChatUnread:
``bool``: On success, True is returned.
"""
return await self.send(
functions.messages.MarkDialogUnread(
return await self.invoke(
raw.functions.messages.MarkDialogUnread(
peer=await self.resolve_peer(chat_id),
unread=True
)

View File

@ -61,7 +61,7 @@ class PinChatMessage:
# Pin without notification
app.pin_chat_message(chat_id, message_id, disable_notification=True)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.UpdatePinnedMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -57,7 +57,7 @@ class PromoteChatMember:
chat_id = await self.resolve_peer(chat_id)
user_id = await self.resolve_peer(user_id)
raw_chat_member = (await self.send(
raw_chat_member = (await self.invoke(
raw.functions.channels.GetParticipant(
channel=chat_id,
participant=user_id
@ -68,7 +68,7 @@ class PromoteChatMember:
if isinstance(raw_chat_member, raw.types.ChannelParticipantAdmin):
rank = raw_chat_member.rank
await self.send(
await self.invoke(
raw.functions.channels.EditAdmin(
channel=chat_id,
user_id=user_id,

View File

@ -72,7 +72,7 @@ class RestrictChatMember:
# Chat member can only send text messages
app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
"""
r = await self.send(
r = await self.invoke(
raw.functions.channels.EditBanned(
channel=await self.resolve_peer(chat_id),
participant=await self.resolve_peer(user_id),

View File

@ -57,7 +57,7 @@ class SetAdministratorTitle:
chat_id = await self.resolve_peer(chat_id)
user_id = await self.resolve_peer(user_id)
r = (await self.send(
r = (await self.invoke(
raw.functions.channels.GetParticipant(
channel=chat_id,
participant=user_id
@ -71,7 +71,7 @@ class SetAdministratorTitle:
else:
raise ValueError("Custom titles can only be applied to owners or administrators of supergroups")
await self.send(
await self.invoke(
raw.functions.channels.EditAdmin(
channel=chat_id,
user_id=user_id,

View File

@ -52,7 +52,7 @@ class SetChatDescription:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, (raw.types.InputPeerChannel, raw.types.InputPeerChat)):
await self.send(
await self.invoke(
raw.functions.messages.EditChatAbout(
peer=peer,
about=description

View File

@ -62,7 +62,7 @@ class SetChatPermissions:
)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditChatDefaultBannedRights(
peer=await self.resolve_peer(chat_id),
banned_rights=raw.types.ChatBannedRights(

View File

@ -100,14 +100,14 @@ class SetChatPhoto:
)
if isinstance(peer, raw.types.InputPeerChat):
await self.send(
await self.invoke(
raw.functions.messages.EditChatPhoto(
chat_id=peer.chat_id,
photo=photo,
)
)
elif isinstance(peer, raw.types.InputPeerChannel):
await self.send(
await self.invoke(
raw.functions.channels.EditPhoto(
channel=peer,
photo=photo

View File

@ -19,7 +19,7 @@
from typing import Union
import pyrogram
from pyrogram.raw import functions
from pyrogram import raw
class SetChatProtectedContent:
@ -41,8 +41,8 @@ class SetChatProtectedContent:
``bool``: On success, True is returned.
"""
await self.send(
functions.messages.ToggleNoForwards(
await self.invoke(
raw.functions.messages.ToggleNoForwards(
peer=await self.resolve_peer(chat_id),
enabled=enabled
)

View File

@ -57,14 +57,14 @@ class SetChatTitle:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChat):
await self.send(
await self.invoke(
raw.functions.messages.EditChatTitle(
chat_id=peer.chat_id,
title=title
)
)
elif isinstance(peer, raw.types.InputPeerChannel):
await self.send(
await self.invoke(
raw.functions.channels.EditTitle(
channel=peer,
title=title

View File

@ -55,7 +55,7 @@ class SetChatUsername:
if isinstance(peer, raw.types.InputPeerChannel):
return bool(
await self.send(
await self.invoke(
raw.functions.channels.UpdateUsername(
channel=peer,
username=username or ""

View File

@ -47,7 +47,7 @@ class SetSendAsChat:
app.set_send_as_chat(chat_id, send_as_chat_id)
"""
return await self.send(
return await self.invoke(
raw.functions.messages.SaveDefaultSendAs(
peer=await self.resolve_peer(chat_id),
send_as=await self.resolve_peer(send_as_chat_id)

View File

@ -51,7 +51,7 @@ class SetSlowMode:
app.set_slow_mode(chat_id, None)
"""
await self.send(
await self.invoke(
raw.functions.channels.ToggleSlowMode(
channel=await self.resolve_peer(chat_id),
seconds=seconds or 0

View File

@ -60,7 +60,7 @@ class UnarchiveChats:
)
)
await self.send(
await self.invoke(
raw.functions.folders.EditPeerFolders(
folder_peers=folder_peers
)

View File

@ -49,7 +49,7 @@ class UnbanChatMember:
# Unban chat member right now
app.unban_chat_member(chat_id, user_id)
"""
await self.send(
await self.invoke(
raw.functions.channels.EditBanned(
channel=await self.resolve_peer(chat_id),
participant=await self.resolve_peer(user_id),

View File

@ -44,7 +44,7 @@ class UnpinAllChatMessages:
# Unpin all chat messages
app.unpin_all_chat_messages(chat_id)
"""
await self.send(
await self.invoke(
raw.functions.messages.UnpinAllMessages(
peer=await self.resolve_peer(chat_id)
)

View File

@ -48,7 +48,7 @@ class UnpinChatMessage:
app.unpin_chat_message(chat_id, message_id)
"""
await self.send(
await self.invoke(
raw.functions.messages.UpdatePinnedMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -60,7 +60,7 @@ class AddContact:
app.add_contact(12345678, "Foo")
app.add_contact("username", "Bar")
"""
r = await self.send(
r = await self.invoke(
raw.functions.contacts.AddContact(
id=await self.resolve_peer(user_id),
first_name=first_name,

View File

@ -50,7 +50,7 @@ class DeleteContacts:
if not is_user_ids_list:
user_ids = [user_ids]
r = await self.send(
r = await self.invoke(
raw.functions.contacts.DeleteContacts(
id=[await self.resolve_peer(i) for i in user_ids]
)

View File

@ -41,5 +41,5 @@ class GetContacts:
contacts = app.get_contacts()
print(contacts)
"""
contacts = await self.send(raw.functions.contacts.GetContacts(hash=0))
contacts = await self.invoke(raw.functions.contacts.GetContacts(hash=0))
return types.List(types.User._parse(self, user) for user in contacts.users)

View File

@ -36,4 +36,4 @@ class GetContactsCount:
print(count)
"""
return len((await self.send(raw.functions.contacts.GetContacts(hash=0))).contacts)
return len((await self.invoke(raw.functions.contacts.GetContacts(hash=0))).contacts)

View File

@ -47,7 +47,7 @@ class ImportContacts:
InputPhoneContact("+1-456-789-0123", "Bar"),
InputPhoneContact("+1-789-012-3456", "Baz")])
"""
imported_contacts = await self.send(
imported_contacts = await self.invoke(
raw.functions.contacts.ImportContacts(
contacts=contacts
)

View File

@ -44,7 +44,7 @@ class ApproveChatJoinRequest:
Returns:
``bool``: True on success.
"""
await self.send(
await self.invoke(
raw.functions.messages.HideChatJoinRequest(
peer=await self.resolve_peer(chat_id),
user_id=await self.resolve_peer(user_id),

View File

@ -72,7 +72,7 @@ class CreateChatInviteLink:
# Create a new link for up to 7 new users
link = app.create_chat_invite_link(chat_id, member_limit=7)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.ExportChatInvite(
peer=await self.resolve_peer(chat_id),
expire_date=utils.datetime_to_timestamp(expire_date),

View File

@ -44,7 +44,7 @@ class DeclineChatJoinRequest:
Returns:
``bool``: True on success.
"""
await self.send(
await self.invoke(
raw.functions.messages.HideChatJoinRequest(
peer=await self.resolve_peer(chat_id),
user_id=await self.resolve_peer(user_id),

View File

@ -44,7 +44,7 @@ class DeleteChatAdminInviteLinks:
``bool``: On success ``True`` is returned.
"""
return await self.send(
return await self.invoke(
raw.functions.messages.DeleteRevokedExportedChatInvites(
peer=await self.resolve_peer(chat_id),
admin_id=await self.resolve_peer(admin_id),

View File

@ -42,7 +42,7 @@ class DeleteChatInviteLink:
``bool``: On success ``True`` is returned.
"""
return await self.send(
return await self.invoke(
raw.functions.messages.DeleteExportedChatInvite(
peer=await self.resolve_peer(chat_id),
link=invite_link,

View File

@ -74,7 +74,7 @@ class EditChatInviteLink:
# Set no expiration date of a link
link = app.edit_chat_invite_link(chat_id, invite_link, expire_date=0)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditExportedChatInvite(
peer=await self.resolve_peer(chat_id),
link=invite_link,

View File

@ -53,7 +53,7 @@ class ExportChatInviteLink:
# Generate a new primary link
link = app.export_chat_invite_link(chat_id)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.ExportChatInvite(
peer=await self.resolve_peer(chat_id),
legacy_revoke_permanent=True

View File

@ -70,7 +70,7 @@ class GetChatAdminInviteLinks:
offset_link = None
while True:
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetExportedChatInvites(
peer=await self.resolve_peer(chat_id),
admin_id=await self.resolve_peer(admin_id),

View File

@ -48,7 +48,7 @@ class GetChatAdminInviteLinksCount:
Returns:
``int``: On success, the invite links count is returned.
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetExportedChatInvites(
peer=await self.resolve_peer(chat_id),
admin_id=await self.resolve_peer(admin_id),

View File

@ -40,7 +40,7 @@ class GetChatAdminsWithInviteLinks:
List of :obj:`~pyrogram.types.ChatAdminWithInviteLink`: On success, the list of admins that have exported
invite links is returned.
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetAdminsWithInvites(
peer=await self.resolve_peer(chat_id)
)

View File

@ -42,7 +42,7 @@ class GetChatInviteLink:
Returns:
:obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned.
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetExportedChatInvite(
peer=await self.resolve_peer(chat_id),
link=invite_link

View File

@ -58,7 +58,7 @@ class GetChatInviteLinkMembers:
offset_user = raw.types.InputUserEmpty()
while True:
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetChatInviteImporters(
peer=await self.resolve_peer(chat_id),
link=invite_link,

View File

@ -41,7 +41,7 @@ class GetChatInviteLinkMembersCount:
Returns:
``int``: On success, the joined chat members count is returned.
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetChatInviteImporters(
peer=await self.resolve_peer(chat_id),
link=invite_link,

View File

@ -47,7 +47,7 @@ class RevokeChatInviteLink:
:obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link object is returned.
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditExportedChatInvite(
peer=await self.resolve_peer(chat_id),
link=invite_link,

View File

@ -109,7 +109,7 @@ class CopyMediaGroup:
)
)
r = await self.send(
r = await self.invoke(
raw.functions.messages.SendMultiMedia(
peer=await self.resolve_peer(chat_id),
multi_media=multi_media,

View File

@ -66,14 +66,14 @@ class DeleteMessages:
message_ids = list(message_ids) if not isinstance(message_ids, int) else [message_ids]
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.send(
r = await self.invoke(
raw.functions.channels.DeleteMessages(
channel=peer,
id=message_ids
)
)
else:
r = await self.send(
r = await self.invoke(
raw.functions.messages.DeleteMessages(
id=message_ids,
revoke=revoke or None

View File

@ -179,7 +179,7 @@ class EditInlineMedia:
session = await get_session(self, dc_id)
return await session.send(
return await session.invoke(
raw.functions.messages.EditInlineBotMessage(
id=unpacked,
media=media,

View File

@ -58,7 +58,7 @@ class EditInlineReplyMarkup:
session = await get_session(self, dc_id)
return await session.send(
return await session.invoke(
raw.functions.messages.EditInlineBotMessage(
id=unpacked,
reply_markup=await reply_markup.write(self) if reply_markup else None,

View File

@ -75,7 +75,7 @@ class EditInlineText:
session = await get_session(self, dc_id)
return await session.send(
return await session.invoke(
raw.functions.messages.EditInlineBotMessage(
id=unpacked,
no_webpage=disable_web_page_preview or None,

View File

@ -87,7 +87,7 @@ class EditMessageMedia:
if isinstance(media, types.InputMediaPhoto):
if os.path.isfile(media.media):
media = await self.send(
media = await self.invoke(
raw.functions.messages.UploadMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaUploadedPhoto(
@ -111,7 +111,7 @@ class EditMessageMedia:
media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO)
elif isinstance(media, types.InputMediaVideo):
if os.path.isfile(media.media):
media = await self.send(
media = await self.invoke(
raw.functions.messages.UploadMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaUploadedDocument(
@ -148,7 +148,7 @@ class EditMessageMedia:
media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO)
elif isinstance(media, types.InputMediaAudio):
if os.path.isfile(media.media):
media = await self.send(
media = await self.invoke(
raw.functions.messages.UploadMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaUploadedDocument(
@ -184,7 +184,7 @@ class EditMessageMedia:
media = utils.get_input_media_from_file_id(media.media, FileType.AUDIO)
elif isinstance(media, types.InputMediaAnimation):
if os.path.isfile(media.media):
media = await self.send(
media = await self.invoke(
raw.functions.messages.UploadMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaUploadedDocument(
@ -222,7 +222,7 @@ class EditMessageMedia:
media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION)
elif isinstance(media, types.InputMediaDocument):
if os.path.isfile(media.media):
media = await self.send(
media = await self.invoke(
raw.functions.messages.UploadMedia(
peer=await self.resolve_peer(chat_id),
media=raw.types.InputMediaUploadedDocument(
@ -252,7 +252,7 @@ class EditMessageMedia:
else:
media = utils.get_input_media_from_file_id(media.media, FileType.DOCUMENT)
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -58,7 +58,7 @@ class EditMessageReplyMarkup:
InlineKeyboardMarkup([[
InlineKeyboardButton("New button", callback_data="new_data")]]))
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -77,7 +77,7 @@ class EditMessageText:
disable_web_page_preview=True)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.EditMessage(
peer=await self.resolve_peer(chat_id),
id=message_id,

View File

@ -79,7 +79,7 @@ class ForwardMessages:
is_iterable = not isinstance(message_ids, int)
message_ids = list(message_ids) if is_iterable else [message_ids]
r = await self.send(
r = await self.invoke(
raw.functions.messages.ForwardMessages(
to_peer=await self.resolve_peer(chat_id),
from_peer=await self.resolve_peer(from_chat_id),

View File

@ -49,7 +49,7 @@ class GetDiscussionMessage:
# Comment to the post by replying
m.reply("comment")
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetDiscussionMessage(
peer=await self.resolve_peer(chat_id),
msg_id=message_id

View File

@ -86,7 +86,7 @@ class GetHistory:
messages = await utils.parse_messages(
self,
await self.send(
await self.invoke(
raw.functions.messages.GetHistory(
peer=await self.resolve_peer(chat_id),
offset_id=offset_id,

View File

@ -51,7 +51,7 @@ class GetHistoryCount:
app.get_history_count(chat_id)
"""
r = await self.send(
r = await self.invoke(
raw.functions.messages.GetHistory(
peer=await self.resolve_peer(chat_id),
offset_id=0,

View File

@ -111,7 +111,7 @@ class GetMessages:
else:
rpc = raw.functions.messages.GetMessages(id=ids)
r = await self.send(rpc, sleep_threshold=-1)
r = await self.invoke(rpc, sleep_threshold=-1)
messages = await utils.parse_messages(self, r, replies=replies)

View File

@ -40,14 +40,14 @@ async def get_session(client: "pyrogram.Client", dc_id: int):
await session.start()
for _ in range(3):
exported_auth = await client.send(
exported_auth = await client.invoke(
raw.functions.auth.ExportAuthorization(
dc_id=dc_id
)
)
try:
await session.send(
await session.invoke(
raw.functions.auth.ImportAuthorization(
id=exported_auth.id,
bytes=exported_auth.bytes

View File

@ -66,6 +66,6 @@ class ReadHistory:
max_id=max_id
)
await self.send(q)
await self.invoke(q)
return True

Some files were not shown because too many files have changed in this diff Show More