-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyrofork: Refactor request_chat/channel/user
Signed-off-by: wulan17 <wulan17@nusantararom.org>
- Loading branch information
Showing
9 changed files
with
256 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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 | ||
from pyrogram import enums, raw, types | ||
from typing import Union | ||
|
||
class RequestedChat(Object): | ||
"""Contains information about a requested chat. | ||
Parameters: | ||
chat_type (``enums.ChatType``): | ||
Type of the chat. | ||
name (``str``, *optional*): | ||
Name of the chat. | ||
username (``str``, *optional*): | ||
Username of the chat. | ||
photo (``types.ChatPhoto``, *optional*): | ||
Chat photo. | ||
""" | ||
def __init__( | ||
self, | ||
chat_type: enums.ChatType, | ||
name: str = None, | ||
username: str = None, | ||
photo: "types.ChatPhoto" = None, | ||
): | ||
super().__init__() | ||
|
||
self.chat_type = chat_type | ||
self.name = name | ||
self.username = username | ||
self.photo = photo | ||
|
||
@staticmethod | ||
async def _parse( | ||
client, | ||
request: Union[ | ||
"raw.types.RequestedPeerChat", | ||
"raw.types.RequestedPeerChannel" | ||
] | ||
) -> "RequestedChat": | ||
if isinstance(request, raw.types.RequestedPeerChannel): | ||
type = enums.ChatType.CHANNEL | ||
else: | ||
type = enums.ChatType.CHAT | ||
return RequestedChat( | ||
chat_type=type, | ||
name=getattr(request, "name", None), | ||
username=getattr(request, "username", None), | ||
photo=await types.ChatPhoto._parse(client, getattr(request, "photo", None)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# 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 | ||
from pyrogram import enums, raw, types | ||
from typing import Union | ||
|
||
class RequestedUser(Object): | ||
"""Contains information about a requested user. | ||
Parameters: | ||
user_id (``int``): | ||
Identifier of the user. | ||
name (``str``, *optional*): | ||
Name of the user. | ||
username (``str``, *optional*): | ||
Username of the user. | ||
photo (``types.UserProfilePhoto``, *optional*): | ||
User photo. | ||
""" | ||
def __init__( | ||
self, | ||
user_id: int, | ||
name: str = None, | ||
username: str = None, | ||
photo: "types.ChatPhoto" = None, | ||
): | ||
super().__init__() | ||
|
||
self.user_id = user_id | ||
self.name = name | ||
self.username = username | ||
self.photo = photo | ||
|
||
@staticmethod | ||
async def _parse( | ||
client, | ||
request: "raw.types.RequestedPeerUser", | ||
) -> "RequestedUser": | ||
user_id = request.user_id | ||
name = request.name | ||
username = request.username | ||
|
||
photo = None | ||
if isinstance(request, raw.types.RequestedPeerUser): | ||
photo = await types.ChatPhoto._parse(client, request.photo) | ||
|
||
return RequestedUser( | ||
user_id=user_id, | ||
name=name, | ||
username=username, | ||
photo=photo | ||
) |
Oops, something went wrong.