Pyrofork: fix {chat,user}_shared

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2023-12-30 16:53:57 +07:00
parent 29ae15e660
commit b524fb6049
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
5 changed files with 76 additions and 67 deletions

View file

@ -18,7 +18,7 @@
from pyrogram import raw, types from pyrogram import raw, types
from ..object import Object from ..object import Object
from typing import Union
class KeyboardButton(Object): class KeyboardButton(Object):
"""One button of the reply keyboard. """One button of the reply keyboard.
@ -38,15 +38,11 @@ class KeyboardButton(Object):
If True, the user's current location will be sent when the button is pressed. If True, the user's current location will be sent when the button is pressed.
Available in private chats only. Available in private chats only.
request_channel ("obj:`~pyrogram.types.RequestPeerTypeChannel`, *optional*): request_chat (:obj:`~pyrogram.types.RequestPeerTypeChannel` | :obj:`~pyrogram.types.RequestPeerTypeChat`, *optional*):
If specified, defines the criteria used to request a suitable channels. If specified, defines the criteria used to request a suitable chats/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. The identifier of the selected chats will be shared with the bot when the corresponding button is pressed.
request_user ("obj:`~pyrogram.types.RequestPeerTypeUser`, *optional*): request_user (:obj:`~pyrogram.types.RequestPeerTypeUser`, *optional*):
If specified, defines the criteria used to request a suitable users. If specified, defines the criteria used to request a suitable users.
The identifier of the selected users will be shared with the bot when the corresponding button is pressed. The identifier of the selected users will be shared with the bot when the corresponding button is pressed.
@ -62,8 +58,7 @@ class KeyboardButton(Object):
text: str, text: str,
request_contact: bool = None, request_contact: bool = None,
request_location: bool = None, request_location: bool = None,
request_channel: "types.RequestPeerTypeChannel" = None, request_chat: Union["types.RequestPeerTypeChat","types.RequestPeerTypeChannel"] = None,
request_chat: "types.RequestPeerTypeChat" = None,
request_user: "types.RequestPeerTypeUser" = None, request_user: "types.RequestPeerTypeUser" = None,
web_app: "types.WebAppInfo" = None web_app: "types.WebAppInfo" = None
): ):
@ -72,7 +67,6 @@ class KeyboardButton(Object):
self.text = str(text) self.text = str(text)
self.request_contact = request_contact self.request_contact = request_contact
self.request_location = request_location self.request_location = request_location
self.request_channel = request_channel
self.request_chat = request_chat self.request_chat = request_chat
self.request_user = request_user self.request_user = request_user
self.web_app = web_app self.web_app = web_app
@ -102,33 +96,36 @@ class KeyboardButton(Object):
) )
) )
if isinstance(b, raw.types.RequestPeerTypeBroadcast): if isinstance(b, raw.types.KeyboardButtonRequestPeer):
return KeyboardButton( if isinstance(b.peer_type, raw.types.RequestPeerTypeBroadcast):
text=b.text, return KeyboardButton(
request_chat=types.RequestPeerTypeChannel( text=b.text,
is_creator=b.creator, request_chat=types.RequestPeerTypeChannel(
is_username=b.has_username is_creator=b.peer_type.creator,
is_username=b.peer_type.has_username,
max=b.max_quantity
)
)
if isinstance(b.peer_type, raw.types.RequestPeerTypeChat):
return KeyboardButton(
text=b.text,
request_chat=types.RequestPeerTypeChat(
is_creator=b.peer_type.creator,
is_bot_participant=b.peer_type.bot_participant,
is_username=b.peer_type.has_username,
is_forum=b.peer_type.forum,
max=b.max_quantity
)
) )
)
if isinstance(b, raw.types.RequestPeerTypeChat): if isinstance(b.peer_type, raw.types.RequestPeerTypeUser):
return KeyboardButton( return KeyboardButton(
text=b.text, text=b.text,
request_chat=types.RequestPeerTypeChat( request_user=types.RequestPeerTypeUser(
is_creator=b.creator, is_bot=b.peer_type.bot,
is_bot_participant=b.bot_participant, is_premium=b.peer_type.premium,
is_username=b.has_username, max=b.max_quantity
is_forum=b.forum )
)
)
if isinstance(b, raw.types.RequestPeerTypeUser):
return KeyboardButton(
text=b.text,
request_user=types.RequestPeerTypeUser(
is_bot=b.bot,
is_premium=b.premium
)
) )
def write(self): def write(self):
@ -136,16 +133,17 @@ class KeyboardButton(Object):
return raw.types.KeyboardButtonRequestPhone(text=self.text) return raw.types.KeyboardButtonRequestPhone(text=self.text)
elif self.request_location: elif self.request_location:
return raw.types.KeyboardButtonRequestGeoLocation(text=self.text) 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: elif self.request_chat:
if isinstance(self.request_chat, types.RequestPeerTypeChannel):
return raw.types.KeyboardButtonRequestPeer(
text=self.text,
button_id=0,
peer_type=raw.types.RequestPeerTypeBroadcast(
creator=self.request_chat.is_creator,
has_username=self.request_chat.is_username
),
max_quantity=self.request_chat.max
)
return raw.types.KeyboardButtonRequestPeer( return raw.types.KeyboardButtonRequestPeer(
text=self.text, text=self.text,
button_id=0, button_id=0,
@ -154,7 +152,8 @@ class KeyboardButton(Object):
bot_participant=self.request_chat.is_bot_participant, bot_participant=self.request_chat.is_bot_participant,
has_username=self.request_chat.is_username, has_username=self.request_chat.is_username,
forum=self.request_chat.is_forum forum=self.request_chat.is_forum
) ),
max_quantity=self.request_chat.max
) )
elif self.request_user: elif self.request_user:
return raw.types.KeyboardButtonRequestPeer( return raw.types.KeyboardButtonRequestPeer(
@ -163,7 +162,8 @@ class KeyboardButton(Object):
peer_type=raw.types.RequestPeerTypeUser( peer_type=raw.types.RequestPeerTypeUser(
bot=self.request_user.is_bot, bot=self.request_user.is_bot,
premium=self.request_user.is_premium premium=self.request_user.is_premium
) ),
max_quantity=self.request_user.max
) )
elif self.web_app: elif self.web_app:
return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url) return raw.types.KeyboardButtonSimpleWebView(text=self.text, url=self.web_app.url)

View file

@ -33,9 +33,11 @@ class RequestPeerTypeChannel(Object):
def __init__( def __init__(
self, self,
is_creator: bool=None, is_creator: bool=None,
is_username: bool=None is_username: bool=None,
max: int=1
): ):
super().__init__() super().__init__()
self.is_creator = is_creator self.is_creator = is_creator
self.is_username = is_username self.is_username = is_username
self.max = max

View file

@ -41,7 +41,8 @@ class RequestPeerTypeChat(Object):
is_creator: bool=None, is_creator: bool=None,
is_bot_participant: bool=None, is_bot_participant: bool=None,
is_username: bool=None, is_username: bool=None,
is_forum: bool=None is_forum: bool=None,
max: int=1
): ):
super().__init__() super().__init__()
@ -49,3 +50,4 @@ class RequestPeerTypeChat(Object):
self.is_bot_participant = is_bot_participant self.is_bot_participant = is_bot_participant
self.is_username = is_username self.is_username = is_username
self.is_forum = is_forum self.is_forum = is_forum
self.max = max

View file

@ -33,9 +33,11 @@ class RequestPeerTypeUser(Object):
def __init__( def __init__(
self, self,
is_bot: bool=None, is_bot: bool=None,
is_premium: bool=None is_premium: bool=None,
max: int=1
): ):
super().__init__() super().__init__()
self.is_bot = is_bot self.is_bot = is_bot
self.is_premium = is_premium self.is_premium = is_premium
self.max = max

View file

@ -322,10 +322,10 @@ class Message(Object, Update):
E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"]. E.g.: "/start 1 2 3" would produce ["start", "1", "2", "3"].
Only applicable when using :obj:`~pyrogram.filters.command`. Only applicable when using :obj:`~pyrogram.filters.command`.
channel_shared (``int``, *optional*): chat_shared (List of ``int``, *optional*):
Service message: chat/channel shared Service message: chat/channel shared
user_shared (``int``, *optional*): user_shared (List of ``int``, *optional*):
Service message: user shared Service message: user shared
forum_topic_created (:obj:`~pyrogram.types.ForumTopicCreated`, *optional*): forum_topic_created (:obj:`~pyrogram.types.ForumTopicCreated`, *optional*):
@ -456,8 +456,8 @@ class Message(Object, Update):
outgoing: bool = None, outgoing: bool = None,
matches: List[Match] = None, matches: List[Match] = None,
command: List[str] = None, command: List[str] = None,
channel_shared: int = None, chat_shared: List[int] = None,
user_shared: int = None, user_shared: List[int] = None,
forum_topic_created: "types.ForumTopicCreated" = None, forum_topic_created: "types.ForumTopicCreated" = None,
forum_topic_closed: "types.ForumTopicClosed" = None, forum_topic_closed: "types.ForumTopicClosed" = None,
forum_topic_reopened: "types.ForumTopicReopened" = None, forum_topic_reopened: "types.ForumTopicReopened" = None,
@ -556,7 +556,7 @@ class Message(Object, Update):
self.matches = matches self.matches = matches
self.command = command self.command = command
self.reply_markup = reply_markup self.reply_markup = reply_markup
self.channel_shared = channel_shared self.chat_shared = chat_shared
self.user_shared = user_shared self.user_shared = user_shared
self.forum_topic_created = forum_topic_created self.forum_topic_created = forum_topic_created
self.forum_topic_closed = forum_topic_closed self.forum_topic_closed = forum_topic_closed
@ -656,7 +656,7 @@ class Message(Object, Update):
group_chat_created = None group_chat_created = None
channel_chat_created = None channel_chat_created = None
new_chat_photo = None new_chat_photo = None
channel_shared = None chat_shared = None
user_shared = None user_shared = None
is_topic_message = None is_topic_message = None
forum_topic_created = None forum_topic_created = None
@ -709,15 +709,18 @@ class Message(Object, Update):
new_chat_photo = types.Photo._parse(client, action.photo) new_chat_photo = types.Photo._parse(client, action.photo)
service_type = enums.MessageServiceType.NEW_CHAT_PHOTO service_type = enums.MessageServiceType.NEW_CHAT_PHOTO
elif isinstance(action, raw.types.MessageActionRequestedPeer): elif isinstance(action, raw.types.MessageActionRequestedPeer):
if isinstance(action.peer, raw.types.PeerChannel): chat_shared = []
channel_shared = utils.get_channel_id(utils.get_raw_peer_id(action.peer)) user_shared = []
service_type = enums.MessageServiceType.ChannelShared for peer in action.peers:
elif isinstance(action.peer, raw.types.PeerChat): if isinstance(peer, raw.types.PeerChannel):
channel_shared = utils.get_channel_id(utils.get_raw_peer_id(action.peer)) chat_shared.append(utils.get_channel_id(utils.get_raw_peer_id(peer)))
service_type = enums.MessageServiceType.ChannelShared service_type = enums.MessageServiceType.ChannelShared
elif isinstance(action.peer, raw.types.PeerUser): elif isinstance(peer, raw.types.PeerChat):
user_shared = action.peer.user_id chat_shared.append(utils.get_channel_id(utils.get_raw_peer_id(peer)))
service_type = enums.MessageServiceType.UserShared service_type = enums.MessageServiceType.ChannelShared
elif isinstance(peer, raw.types.PeerUser):
user_shared.append(peer.user_id)
service_type = enums.MessageServiceType.UserShared
elif isinstance(action, raw.types.MessageActionTopicCreate): elif isinstance(action, raw.types.MessageActionTopicCreate):
forum_topic_created = types.ForumTopicCreated._parse(message) forum_topic_created = types.ForumTopicCreated._parse(message)
service_type = enums.MessageServiceType.FORUM_TOPIC_CREATED service_type = enums.MessageServiceType.FORUM_TOPIC_CREATED
@ -782,8 +785,8 @@ class Message(Object, Update):
migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None, migrate_from_chat_id=-migrate_from_chat_id if migrate_from_chat_id else None,
group_chat_created=group_chat_created, group_chat_created=group_chat_created,
channel_chat_created=channel_chat_created, channel_chat_created=channel_chat_created,
channel_shared=channel_shared, chat_shared=chat_shared if chat_shared is not None and len(chat_shared) > 0 else None,
user_shared=user_shared, user_shared=user_shared if user_shared is not None and len(user_shared) > 0 else None,
is_topic_message=is_topic_message, is_topic_message=is_topic_message,
forum_topic_created=forum_topic_created, forum_topic_created=forum_topic_created,
forum_topic_closed=forum_topic_closed, forum_topic_closed=forum_topic_closed,