Skip to content

Commit

Permalink
Pyrogram: Add request_channel parameters
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Aug 2, 2023
1 parent fcee67f commit fca39fa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyrogram/types/bots_and_keyboards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from .menu_button_web_app import MenuButtonWebApp
from .reply_keyboard_markup import ReplyKeyboardMarkup
from .reply_keyboard_remove import ReplyKeyboardRemove
from .request_peer_type_channel import RequestPeerTypeChannel
from .request_peer_type_chat import RequestPeerTypeChat
from .request_peer_type_user import RequestPeerTypeUser
from .sent_web_app_message import SentWebAppMessage
Expand All @@ -55,6 +56,7 @@
"KeyboardButton",
"ReplyKeyboardMarkup",
"ReplyKeyboardRemove",
"RequestPeerTypeChannel",
"RequestPeerTypeChat",
"RequestPeerTypeUser",
"LoginUrl",
Expand Down
24 changes: 24 additions & 0 deletions pyrogram/types/bots_and_keyboards/keyboard_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class KeyboardButton(Object):
If True, the user's current location will be sent when the button is pressed.
Available in private chats only.
request_channel ("obj:`~pyrogram.types.RequestPeerTypeChannel`, *optional*):
If specified, defines the criteria used to request a suitable channels.
The identifier of the selected channels will be shared with the bot when the corresponding button is pressed.
request_chat ("obj:`~pyrogram.types.RequestPeerTypeChat`, *optional*):
If specified, defines the criteria used to request a suitable chats.
The identifier of the selected chats will be shared with the bot when the corresponding button is pressed.
Expand All @@ -58,6 +62,7 @@ def __init__(
text: str,
request_contact: bool = None,
request_location: bool = None,
request_channel: "types.RequestPeerTypeChannel" = None,
request_chat: "types.RequestPeerTypeChat" = None,
request_user: "types.RequestPeerTypeUser" = None,
web_app: "types.WebAppInfo" = None
Expand All @@ -67,6 +72,7 @@ def __init__(
self.text = str(text)
self.request_contact = request_contact
self.request_location = request_location
self.request_channel = request_channel
self.request_chat = request_chat
self.request_user = request_user
self.web_app = web_app
Expand Down Expand Up @@ -96,6 +102,15 @@ def read(b):
)
)

if isinstance(b, raw.types.RequestPeerTypeBroadcast):
return KeyboardButton(
text=b.text,
request_chat=types.RequestPeerTypeChannel(
is_creator=b.creator,
is_username=b.has_username
)
)

if isinstance(b, raw.types.RequestPeerTypeChat):
return KeyboardButton(
text=b.text,
Expand All @@ -121,6 +136,15 @@ def write(self):
return raw.types.KeyboardButtonRequestPhone(text=self.text)
elif self.request_location:
return raw.types.KeyboardButtonRequestGeoLocation(text=self.text)
elif self.request_channel:
return raw.types.KeyboardButtonRequestPeer(
text=self.text,
button_id=0,
peer_type=raw.types.RequestPeerTypeBroadcast(
creator=self.request_broadcast.is_creator,
has_username=self.request_broadcast.is_username
)
)
elif self.request_chat:
return raw.types.KeyboardButtonRequestPeer(
text=self.text,
Expand Down
41 changes: 41 additions & 0 deletions pyrogram/types/bots_and_keyboards/request_peer_type_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrofork.
#
# Pyrofork 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.
#
# Pyrofork 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 Pyrofork. If not, see <http://www.gnu.org/licenses/>.

from ..object import Object


class RequestPeerTypeChannel(Object):
"""Object used to request clients to send a channel identifier.
Parameters:
is_creator (``bool``, *optional*):
If True, show only Channel which user is the owner.
is_username (``bool``, *optional*):
If True, show only Channel which has username.
""" # TODO user_admin_rights, bot_admin_rights

def __init__(
self,
is_creator: bool=None,
is_username: bool=None
):
super().__init__()

self.is_creator = is_creator
self.is_username = is_username

0 comments on commit fca39fa

Please sign in to comment.