From 6c976a37082ef9f4a82b77145052af2c00b32841 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:41:06 +0200 Subject: [PATCH 1/8] Update README.rst --- README.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 67dbd3a5..eb49c635 100644 --- a/README.rst +++ b/README.rst @@ -12,12 +12,11 @@ Pyrogram |twitter| @app.on_message(Filters.private) def hello(client, message): - client.send_message( - message.chat.id, "Hello {}".format(message.from_user.first_name)) + message.reply_text( + "Hello {}".format(message.from_user.first_name)) - app.start() - app.idle() + app.run() **Pyrogram** is a brand new Telegram_ Client Library written from the ground up in Python and C. It can be used for building custom Telegram applications that interact with the MTProto API as both User and Bot. From 8074ef1368259a20c5d6d9b01dfa87436ed0da20 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 10:34:20 +0200 Subject: [PATCH 2/8] Make methods directory structure simple --- pyrogram/client/methods/bots/__init__.py | 12 +++-- .../answer_callback_query.py | 2 +- .../methods/bots/callback_query/__init__.py | 25 ---------- .../{inline => }/get_inline_bot_results.py | 2 +- .../client/methods/bots/inline/__init__.py | 27 ----------- .../{inline => }/send_inline_bot_result.py | 2 +- pyrogram/client/methods/messages/__init__.py | 44 +++++++++++++---- .../methods/messages/action/__init__.py | 25 ---------- .../messages/{update => }/delete_messages.py | 2 +- .../{update => }/edit_message_caption.py | 2 +- .../{update => }/edit_message_reply_markup.py | 2 +- .../{update => }/edit_message_text.py | 2 +- .../client/methods/messages/media/__init__.py | 47 ------------------- .../messages/{media => }/send_audio.py | 2 +- .../messages/{action => }/send_chat_action.py | 2 +- .../messages/{media => }/send_contact.py | 2 +- .../messages/{media => }/send_document.py | 2 +- .../methods/messages/{media => }/send_gif.py | 2 +- .../messages/{media => }/send_location.py | 2 +- .../messages/{media => }/send_media_group.py | 2 +- .../messages/{media => }/send_photo.py | 2 +- .../messages/{media => }/send_sticker.py | 2 +- .../messages/{media => }/send_venue.py | 2 +- .../messages/{media => }/send_video.py | 2 +- .../messages/{media => }/send_video_note.py | 2 +- .../messages/{media => }/send_voice.py | 2 +- .../methods/messages/update/__init__.py | 31 ------------ 27 files changed, 64 insertions(+), 187 deletions(-) rename pyrogram/client/methods/bots/{callback_query => }/answer_callback_query.py (98%) delete mode 100644 pyrogram/client/methods/bots/callback_query/__init__.py rename pyrogram/client/methods/bots/{inline => }/get_inline_bot_results.py (98%) delete mode 100644 pyrogram/client/methods/bots/inline/__init__.py rename pyrogram/client/methods/bots/{inline => }/send_inline_bot_result.py (98%) delete mode 100644 pyrogram/client/methods/messages/action/__init__.py rename pyrogram/client/methods/messages/{update => }/delete_messages.py (98%) rename pyrogram/client/methods/messages/{update => }/edit_message_caption.py (98%) rename pyrogram/client/methods/messages/{update => }/edit_message_reply_markup.py (98%) rename pyrogram/client/methods/messages/{update => }/edit_message_text.py (98%) delete mode 100644 pyrogram/client/methods/messages/media/__init__.py rename pyrogram/client/methods/messages/{media => }/send_audio.py (99%) rename pyrogram/client/methods/messages/{action => }/send_chat_action.py (98%) rename pyrogram/client/methods/messages/{media => }/send_contact.py (98%) rename pyrogram/client/methods/messages/{media => }/send_document.py (99%) rename pyrogram/client/methods/messages/{media => }/send_gif.py (99%) rename pyrogram/client/methods/messages/{media => }/send_location.py (98%) rename pyrogram/client/methods/messages/{media => }/send_media_group.py (99%) rename pyrogram/client/methods/messages/{media => }/send_photo.py (99%) rename pyrogram/client/methods/messages/{media => }/send_sticker.py (99%) rename pyrogram/client/methods/messages/{media => }/send_venue.py (98%) rename pyrogram/client/methods/messages/{media => }/send_video.py (99%) rename pyrogram/client/methods/messages/{media => }/send_video_note.py (99%) rename pyrogram/client/methods/messages/{media => }/send_voice.py (99%) delete mode 100644 pyrogram/client/methods/messages/update/__init__.py diff --git a/pyrogram/client/methods/bots/__init__.py b/pyrogram/client/methods/bots/__init__.py index 62e0eb61..2d89c2fb 100644 --- a/pyrogram/client/methods/bots/__init__.py +++ b/pyrogram/client/methods/bots/__init__.py @@ -16,12 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .callback_query import CallbackQuery -from .inline import Inline +from .answer_callback_query import AnswerCallbackQuery +from .get_inline_bot_results import GetInlineBotResults +from .request_callback_answer import RequestCallbackAnswer +from .send_inline_bot_result import SendInlineBotResult class Bots( - CallbackQuery, - Inline + AnswerCallbackQuery, + GetInlineBotResults, + RequestCallbackAnswer, + SendInlineBotResult ): pass diff --git a/pyrogram/client/methods/bots/callback_query/answer_callback_query.py b/pyrogram/client/methods/bots/answer_callback_query.py similarity index 98% rename from pyrogram/client/methods/bots/callback_query/answer_callback_query.py rename to pyrogram/client/methods/bots/answer_callback_query.py index a4baa166..64951692 100644 --- a/pyrogram/client/methods/bots/callback_query/answer_callback_query.py +++ b/pyrogram/client/methods/bots/answer_callback_query.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions -from ....ext import BaseClient +from pyrogram.client.ext import BaseClient class AnswerCallbackQuery(BaseClient): diff --git a/pyrogram/client/methods/bots/callback_query/__init__.py b/pyrogram/client/methods/bots/callback_query/__init__.py deleted file mode 100644 index 76575724..00000000 --- a/pyrogram/client/methods/bots/callback_query/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -from .answer_callback_query import AnswerCallbackQuery - - -class CallbackQuery( - AnswerCallbackQuery -): - pass diff --git a/pyrogram/client/methods/bots/inline/get_inline_bot_results.py b/pyrogram/client/methods/bots/get_inline_bot_results.py similarity index 98% rename from pyrogram/client/methods/bots/inline/get_inline_bot_results.py rename to pyrogram/client/methods/bots/get_inline_bot_results.py index 52c3b005..a43eb6c1 100644 --- a/pyrogram/client/methods/bots/inline/get_inline_bot_results.py +++ b/pyrogram/client/methods/bots/get_inline_bot_results.py @@ -18,7 +18,7 @@ from pyrogram.api import functions, types from pyrogram.api.errors import UnknownError -from ....ext import BaseClient +from pyrogram.client.ext import BaseClient class GetInlineBotResults(BaseClient): diff --git a/pyrogram/client/methods/bots/inline/__init__.py b/pyrogram/client/methods/bots/inline/__init__.py deleted file mode 100644 index af88c57e..00000000 --- a/pyrogram/client/methods/bots/inline/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -from .get_inline_bot_results import GetInlineBotResults -from .send_inline_bot_result import SendInlineBotResult - - -class Inline( - SendInlineBotResult, - GetInlineBotResults -): - pass diff --git a/pyrogram/client/methods/bots/inline/send_inline_bot_result.py b/pyrogram/client/methods/bots/send_inline_bot_result.py similarity index 98% rename from pyrogram/client/methods/bots/inline/send_inline_bot_result.py rename to pyrogram/client/methods/bots/send_inline_bot_result.py index 947433cd..c194298a 100644 --- a/pyrogram/client/methods/bots/inline/send_inline_bot_result.py +++ b/pyrogram/client/methods/bots/send_inline_bot_result.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions -from ....ext import BaseClient +from pyrogram.client.ext import BaseClient class SendInlineBotResult(BaseClient): diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index c2ff2400..e2c2462e 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -16,22 +16,50 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .action import Action +from .delete_messages import DeleteMessages +from .edit_message_caption import EditMessageCaption +from .edit_message_reply_markup import EditMessageReplyMarkup +from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages from .get_history import GetHistory from .get_messages import GetMessages -from .media import Media +from .send_audio import SendAudio +from .send_chat_action import SendChatAction +from .send_contact import SendContact +from .send_document import SendDocument +from .send_gif import SendGIF +from .send_location import SendLocation +from .send_media_group import SendMediaGroup from .send_message import SendMessage -from .update import Update +from .send_photo import SendPhoto +from .send_sticker import SendSticker +from .send_venue import SendVenue +from .send_video import SendVideo +from .send_video_note import SendVideoNote +from .send_voice import SendVoice class Messages( + DeleteMessages, + EditMessageCaption, + EditMessageReplyMarkup, + EditMessageText, + ForwardMessages, GetHistory, GetMessages, - Action, - Media, - Update, - ForwardMessages, - SendMessage + SendAudio, + SendChatAction, + SendContact, + SendDocument, + SendGIF, + SendLocation, + SendMediaGroup, + SendMessage, + SendPhoto, + SendSticker, + SendVenue, + SendVideo, + SendVideoNote, + SendVoice ): pass diff --git a/pyrogram/client/methods/messages/action/__init__.py b/pyrogram/client/methods/messages/action/__init__.py deleted file mode 100644 index 639405f2..00000000 --- a/pyrogram/client/methods/messages/action/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -from .send_chat_action import SendChatAction - - -class Action( - SendChatAction -): - pass diff --git a/pyrogram/client/methods/messages/update/delete_messages.py b/pyrogram/client/methods/messages/delete_messages.py similarity index 98% rename from pyrogram/client/methods/messages/update/delete_messages.py rename to pyrogram/client/methods/messages/delete_messages.py index 3d29bf55..a4c97c76 100644 --- a/pyrogram/client/methods/messages/update/delete_messages.py +++ b/pyrogram/client/methods/messages/delete_messages.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient +from pyrogram.client.ext import BaseClient class DeleteMessages(BaseClient): diff --git a/pyrogram/client/methods/messages/update/edit_message_caption.py b/pyrogram/client/methods/messages/edit_message_caption.py similarity index 98% rename from pyrogram/client/methods/messages/update/edit_message_caption.py rename to pyrogram/client/methods/messages/edit_message_caption.py index 90bf26f7..25276dc2 100644 --- a/pyrogram/client/methods/messages/update/edit_message_caption.py +++ b/pyrogram/client/methods/messages/edit_message_caption.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class EditMessageCaption(BaseClient): diff --git a/pyrogram/client/methods/messages/update/edit_message_reply_markup.py b/pyrogram/client/methods/messages/edit_message_reply_markup.py similarity index 98% rename from pyrogram/client/methods/messages/update/edit_message_reply_markup.py rename to pyrogram/client/methods/messages/edit_message_reply_markup.py index 295eb258..b840adab 100644 --- a/pyrogram/client/methods/messages/update/edit_message_reply_markup.py +++ b/pyrogram/client/methods/messages/edit_message_reply_markup.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class EditMessageReplyMarkup(BaseClient): diff --git a/pyrogram/client/methods/messages/update/edit_message_text.py b/pyrogram/client/methods/messages/edit_message_text.py similarity index 98% rename from pyrogram/client/methods/messages/update/edit_message_text.py rename to pyrogram/client/methods/messages/edit_message_text.py index be7b380c..741c0890 100644 --- a/pyrogram/client/methods/messages/update/edit_message_text.py +++ b/pyrogram/client/methods/messages/edit_message_text.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class EditMessageText(BaseClient): diff --git a/pyrogram/client/methods/messages/media/__init__.py b/pyrogram/client/methods/messages/media/__init__.py deleted file mode 100644 index b0e287c5..00000000 --- a/pyrogram/client/methods/messages/media/__init__.py +++ /dev/null @@ -1,47 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -from .send_audio import SendAudio -from .send_contact import SendContact -from .send_document import SendDocument -from .send_gif import SendGIF -from .send_location import SendLocation -from .send_media_group import SendMediaGroup -from .send_photo import SendPhoto -from .send_sticker import SendSticker -from .send_venue import SendVenue -from .send_video import SendVideo -from .send_video_note import SendVideoNote -from .send_voice import SendVoice - - -class Media( - SendContact, - SendVenue, - SendLocation, - SendMediaGroup, - SendVideoNote, - SendVoice, - SendVideo, - SendGIF, - SendSticker, - SendDocument, - SendAudio, - SendPhoto -): - pass diff --git a/pyrogram/client/methods/messages/media/send_audio.py b/pyrogram/client/methods/messages/send_audio.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_audio.py rename to pyrogram/client/methods/messages/send_audio.py index 41f4457f..7d590b79 100644 --- a/pyrogram/client/methods/messages/media/send_audio.py +++ b/pyrogram/client/methods/messages/send_audio.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendAudio(BaseClient): diff --git a/pyrogram/client/methods/messages/action/send_chat_action.py b/pyrogram/client/methods/messages/send_chat_action.py similarity index 98% rename from pyrogram/client/methods/messages/action/send_chat_action.py rename to pyrogram/client/methods/messages/send_chat_action.py index 4b34dd40..49625b48 100644 --- a/pyrogram/client/methods/messages/action/send_chat_action.py +++ b/pyrogram/client/methods/messages/send_chat_action.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions -from ....ext import BaseClient, ChatAction +from pyrogram.client.ext import BaseClient, ChatAction class SendChatAction(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_contact.py b/pyrogram/client/methods/messages/send_contact.py similarity index 98% rename from pyrogram/client/methods/messages/media/send_contact.py rename to pyrogram/client/methods/messages/send_contact.py index eb1bb6c4..fc0abdd5 100644 --- a/pyrogram/client/methods/messages/media/send_contact.py +++ b/pyrogram/client/methods/messages/send_contact.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendContact(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_document.py b/pyrogram/client/methods/messages/send_document.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_document.py rename to pyrogram/client/methods/messages/send_document.py index 1092147f..b2b5c532 100644 --- a/pyrogram/client/methods/messages/media/send_document.py +++ b/pyrogram/client/methods/messages/send_document.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendDocument(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_gif.py b/pyrogram/client/methods/messages/send_gif.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_gif.py rename to pyrogram/client/methods/messages/send_gif.py index 0d4bb4b9..a4a14d84 100644 --- a/pyrogram/client/methods/messages/media/send_gif.py +++ b/pyrogram/client/methods/messages/send_gif.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendGIF(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_location.py b/pyrogram/client/methods/messages/send_location.py similarity index 98% rename from pyrogram/client/methods/messages/media/send_location.py rename to pyrogram/client/methods/messages/send_location.py index 08dac02b..a3db2561 100644 --- a/pyrogram/client/methods/messages/media/send_location.py +++ b/pyrogram/client/methods/messages/send_location.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendLocation(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_media_group.py b/pyrogram/client/methods/messages/send_media_group.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_media_group.py rename to pyrogram/client/methods/messages/send_media_group.py index 6d004d9f..297d8f83 100644 --- a/pyrogram/client/methods/messages/media/send_media_group.py +++ b/pyrogram/client/methods/messages/send_media_group.py @@ -24,7 +24,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid from pyrogram.client import types as pyrogram_types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendMediaGroup(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_photo.py b/pyrogram/client/methods/messages/send_photo.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_photo.py rename to pyrogram/client/methods/messages/send_photo.py index 52e98ff1..a6264bf3 100644 --- a/pyrogram/client/methods/messages/media/send_photo.py +++ b/pyrogram/client/methods/messages/send_photo.py @@ -22,7 +22,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendPhoto(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_sticker.py b/pyrogram/client/methods/messages/send_sticker.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_sticker.py rename to pyrogram/client/methods/messages/send_sticker.py index 639e3600..fbf7a205 100644 --- a/pyrogram/client/methods/messages/media/send_sticker.py +++ b/pyrogram/client/methods/messages/send_sticker.py @@ -22,7 +22,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendSticker(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_venue.py b/pyrogram/client/methods/messages/send_venue.py similarity index 98% rename from pyrogram/client/methods/messages/media/send_venue.py rename to pyrogram/client/methods/messages/send_venue.py index d65ea43b..50946e86 100644 --- a/pyrogram/client/methods/messages/media/send_venue.py +++ b/pyrogram/client/methods/messages/send_venue.py @@ -17,7 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api import functions, types -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendVenue(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_video.py b/pyrogram/client/methods/messages/send_video.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_video.py rename to pyrogram/client/methods/messages/send_video.py index a4cc0309..b86b4702 100644 --- a/pyrogram/client/methods/messages/media/send_video.py +++ b/pyrogram/client/methods/messages/send_video.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendVideo(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_video_note.py b/pyrogram/client/methods/messages/send_video_note.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_video_note.py rename to pyrogram/client/methods/messages/send_video_note.py index d7b417d5..a266e5dd 100644 --- a/pyrogram/client/methods/messages/media/send_video_note.py +++ b/pyrogram/client/methods/messages/send_video_note.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendVideoNote(BaseClient): diff --git a/pyrogram/client/methods/messages/media/send_voice.py b/pyrogram/client/methods/messages/send_voice.py similarity index 99% rename from pyrogram/client/methods/messages/media/send_voice.py rename to pyrogram/client/methods/messages/send_voice.py index ae21de6d..f4fe4229 100644 --- a/pyrogram/client/methods/messages/media/send_voice.py +++ b/pyrogram/client/methods/messages/send_voice.py @@ -23,7 +23,7 @@ import struct from pyrogram.api import functions, types from pyrogram.api.errors import FileIdInvalid, FilePartMissing -from ....ext import BaseClient, utils +from pyrogram.client.ext import BaseClient, utils class SendVoice(BaseClient): diff --git a/pyrogram/client/methods/messages/update/__init__.py b/pyrogram/client/methods/messages/update/__init__.py deleted file mode 100644 index cc913e23..00000000 --- a/pyrogram/client/methods/messages/update/__init__.py +++ /dev/null @@ -1,31 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# This file is part of Pyrogram. -# -# Pyrogram is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pyrogram is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with Pyrogram. If not, see . - -from .delete_messages import DeleteMessages -from .edit_message_caption import EditMessageCaption -from .edit_message_reply_markup import EditMessageReplyMarkup -from .edit_message_text import EditMessageText - - -class Update( - DeleteMessages, - EditMessageReplyMarkup, - EditMessageCaption, - EditMessageText -): - pass From 6404862b878ba7c6deff3046d236d71c0ff26946 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 10:36:29 +0200 Subject: [PATCH 3/8] Add reply_keyboard and inline_keyboard filters --- pyrogram/client/filters/filters.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/filters/filters.py b/pyrogram/client/filters/filters.py index 26aa84c8..133ab6c2 100644 --- a/pyrogram/client/filters/filters.py +++ b/pyrogram/client/filters/filters.py @@ -19,6 +19,7 @@ import re from .filter import Filter +from ..types.reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup def build(name: str, func: callable, **kwargs) -> type: @@ -131,7 +132,11 @@ class Filters: pinned_message = build("PinnedMessage", lambda _, m: bool(m.pinned_message)) """Filter service messages for pinned messages.""" - # TODO: Add filters for reply markups + reply_keyboard = build("ReplyKeyboard", lambda _, m: isinstance(m.reply_markup, ReplyKeyboardMarkup)) + """Filter messages containing reply keyboard markups""" + + inline_keyboard = build("InlineKeyboard", lambda _, m: isinstance(m.reply_markup, InlineKeyboardMarkup)) + """Filter messages containing inline keyboard markups""" @staticmethod def command(command: str or list, From 2ee7cf5124c43d5ad8cd0840dbe8b144db0395fc Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 12:29:40 +0200 Subject: [PATCH 4/8] Add request_callback_answer method --- .../methods/bots/request_callback_answer.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pyrogram/client/methods/bots/request_callback_answer.py diff --git a/pyrogram/client/methods/bots/request_callback_answer.py b/pyrogram/client/methods/bots/request_callback_answer.py new file mode 100644 index 00000000..5bc31efd --- /dev/null +++ b/pyrogram/client/methods/bots/request_callback_answer.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from pyrogram.api import functions +from pyrogram.client.ext import BaseClient + + +class RequestCallbackAnswer(BaseClient): + def request_callback_answer(self, + chat_id: int or str, + message_id: int, + callback_data: str): + """Use this method to request a callback answer from bots. This is the equivalent of clicking an inline button + containing callback data. The answer contains info useful for clients to display a notification at the top of + the chat screen or as an alert. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + For a private channel/supergroup you can use its *t.me/joinchat/* link. + + message_id (``int``): + The message id the inline keyboard is attached on. + + callback_data (``str``): + Callback data associated with the inline button you want to get the answer from. + """ + return self.send( + functions.messages.GetBotCallbackAnswer( + peer=self.resolve_peer(chat_id), + msg_id=message_id, + data=callback_data.encode() + ) + ) From d95086163e4b68b3431d8327a77c37c9c4473c60 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 14:09:07 +0200 Subject: [PATCH 5/8] Add click() bound method to Message --- pyrogram/client/types/message.py | 113 +++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 74f2a0a6..43eaba2a 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from pyrogram.api.core import Object +from .reply_markup import InlineKeyboardMarkup, ReplyKeyboardMarkup class Message(Object): @@ -460,3 +461,115 @@ class Message(Object): ) return True + + def click(self, x: int or str, y: int = None, quote: bool = None): + """Use this method to click a button attached to the message. + It's a shortcut for: + + - Clicking inline buttons: + + .. code-block:: python + + client.request_callback_answer( + chat_id=message.chat.id, + message_id=message.message_id, + callback_data=message.reply_markup[i][j].callback_data + ) + + - Clicking normal buttons: + + .. code-block:: python + + client.send_message( + chat_id=message.chat.id, + text=message.reply_markup[i][j].text + ) + + This method can be used in three different ways: + + 1. Pass one integer argument only (e.g.: ``.click(2)``, to click a button at index 2). + Buttons are counted left to right, starting from the top. + + 2. Pass two integer arguments (e.g.: ``.click(1, 0)``, to click a button at position (1, 0)). + The origin (0, 0) is top-left. + + 3. Pass one string argument only (e.g.: ``.click("Settings")``, to click a button by using its label). + Only the first matching button will be pressed. + + Args: + x (``int`` | ``str``): + Used as integer index, integer abscissa (in pair with y) or as string label. + + y (``int``, *optional*): + Used as ordinate only (in pair with x). + + quote (``bool``, *optional*): + Useful for normal buttons only, where pressing it will result in a new message sent. + If ``True``, the message will be sent as a reply to this message. + Defaults to ``True`` in group chats and ``False`` in private chats. + + Returns: + - The result of *request_callback_answer()* in case of inline callback button clicks. + - The result of *reply_text()* in case of normal button clicks. + - A string in case the inline button is an URL, switch_inline_query or switch_inline_query_current_chat + button. + + Raises: + :class:`Error ` + ``ValueError``: If the provided index or position is out of range or the button label was not found. + """ + if isinstance(self.reply_markup, ReplyKeyboardMarkup): + if quote is None: + quote = self.chat.type != "private" + + return self.reply_text(x, quote=quote) + elif isinstance(self.reply_markup, InlineKeyboardMarkup): + if isinstance(x, int) and y is None: + try: + button = [ + button + for row in self.reply_markup.inline_keyboard + for button in row + ][x] + except IndexError: + raise ValueError("The button at index {} doesn't exist".format(x)) from None + elif isinstance(x, int) and isinstance(y, int): + try: + button = self.reply_markup.inline_keyboard[y][x] + except IndexError: + raise ValueError("The button at position ({}, {}) doesn't exist".format(x, y)) from None + elif isinstance(x, str): + x = x.encode("utf-16", "surrogatepass").decode("utf-16") + + try: + button = [ + button + for row in self.reply_markup.inline_keyboard + for button in row + if x == button.text + ][0] + except IndexError: + raise ValueError( + "The button with label '{}' doesn't exists".format( + x.encode("unicode_escape").decode() + ) + ) from None + else: + raise ValueError("Invalid arguments") + + if button.callback_data: + return self._client.request_callback_answer( + chat_id=self.chat.id, + message_id=self.message_id, + data=button.callback_data + ) + elif button.url: + return button.url + elif button.switch_inline_query: + return button.switch_inline_query + elif button.switch_inline_query_current_chat: + return button.switch_inline_query_current_chat + else: + raise ValueError("This button is not supported yet") + else: + raise ValueError("The message doesn't contain any keyboard") From 03a17dd8dbd9b5081113341a142c340694635b34 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 14:24:31 +0200 Subject: [PATCH 6/8] Rename reply_text() to reply() Is shorter and looks nicer. When more methods like reply_audio(), reply_photo(), etc. will be implemented, I can consider adding reply_text() back again, maybe. --- pyrogram/client/types/message.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/types/message.py b/pyrogram/client/types/message.py index 43eaba2a..8f677a2d 100644 --- a/pyrogram/client/types/message.py +++ b/pyrogram/client/types/message.py @@ -311,14 +311,14 @@ class Message(Object): self.command = command self.reply_markup = reply_markup - def reply_text(self, - text: str, - quote: bool = None, - parse_mode: str = "", - disable_web_page_preview: bool = None, - disable_notification: bool = None, - reply_to_message_id: int = None, - reply_markup=None): + def reply(self, + text: str, + quote: bool = None, + parse_mode: str = "", + disable_web_page_preview: bool = None, + disable_notification: bool = None, + reply_to_message_id: int = None, + reply_markup=None): """Use this method as a shortcut for: .. code-block:: python @@ -510,7 +510,7 @@ class Message(Object): Returns: - The result of *request_callback_answer()* in case of inline callback button clicks. - - The result of *reply_text()* in case of normal button clicks. + - The result of *reply()* in case of normal button clicks. - A string in case the inline button is an URL, switch_inline_query or switch_inline_query_current_chat button. @@ -522,7 +522,7 @@ class Message(Object): if quote is None: quote = self.chat.type != "private" - return self.reply_text(x, quote=quote) + return self.reply(x, quote=quote) elif isinstance(self.reply_markup, InlineKeyboardMarkup): if isinstance(x, int) and y is None: try: From 25a09d1c9b281c2d1f617df1517eb24ccbab088b Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 14:25:19 +0200 Subject: [PATCH 7/8] Update docs welcome example --- docs/source/index.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 414e47dd..c52e239b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -44,8 +44,7 @@ Welcome to Pyrogram @app.on_message(Filters.private) def hello(client, message): - message.reply_text( - "Hello {}".format(message.from_user.first_name)) + message.reply("Hello {}".format(message.from_user.first_name)) app.run() From 69ca31b12ec98b9ba09782a8274a67fb9e876835 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 23 Jun 2018 14:26:23 +0200 Subject: [PATCH 8/8] Update README.rst --- README.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rst b/README.rst index eb49c635..b1015db2 100644 --- a/README.rst +++ b/README.rst @@ -12,8 +12,7 @@ Pyrogram |twitter| @app.on_message(Filters.private) def hello(client, message): - message.reply_text( - "Hello {}".format(message.from_user.first_name)) + message.reply("Hello {}".format(message.from_user.first_name)) app.run()