Skip to content

Commit

Permalink
pyrofork: Add BotVerification Types
Browse files Browse the repository at this point in the history
Signed-off-by: Yasir <[email protected]>
  • Loading branch information
yasirarism committed Jan 9, 2025
1 parent f5ce0f7 commit d032c3a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ def get_title_list(s: str) -> list:
BotInfo
ChatColor
CollectibleItemInfo
BotVerification
""",
messages_media="""
Messages & Media
Expand Down Expand Up @@ -780,7 +781,6 @@ def get_title_list(s: str) -> list:
Message.react
Message.translate
Message.wait_for_click
UserGift.toggle
""",
chat="""
Chat
Expand Down
2 changes: 2 additions & 0 deletions pyrogram/types/user_and_chats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.

from .birthday import Birthday
from .bot_verification import BotVerification
from .business_info import BusinessInfo
from .business_message import BusinessMessage
from .business_recipients import BusinessRecipients
Expand Down Expand Up @@ -62,6 +63,7 @@

__all__ = [
"Birthday",
"BotVerification",
"BusinessInfo",
"BusinessMessage",
"BusinessRecipients",
Expand Down
63 changes: 63 additions & 0 deletions pyrogram/types/user_and_chats/bot_verification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# 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 <http://www.gnu.org/licenses/>.

from typing import Optional

from pyrogram import raw, types
from ..object import Object


class BotVerification(Object):
"""Information about bot verification.
Parameters:
bot (:obj:`~pyrogram.types.User`):
Bot that is verified this user.
custom_emoji_id (``int``):
Custom emoji icon identifier.
description (``int``, *optional*):
Additional description about the verification.
"""

def __init__(
self,
*,
bot: int,
custom_emoji_id: int,
description: str
):
self.bot = bot
self.custom_emoji_id = custom_emoji_id
self.description = description

@staticmethod
def _parse(
client,
verification: "raw.types.BotVerification",
users
) -> Optional["BotVerification"]:
if not verification:
return None

return BotVerification(
bot=types.User._parse(client, users.get(verification.bot_id)),
custom_emoji_id=verification.icon,
description=verification.description
)
18 changes: 15 additions & 3 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class Chat(Object):
subscription_until_date (:py:obj:`~datetime.datetime`, *optional*):
Channel members only. Date when the subscription expires.
gifts_count (``int``, *optional*):
Number of gifts received by the user.
bot_verification (:obj:`~pyrogram.types.BotVerification`, *optional*):
Information about bot verification.
"""

def __init__(
Expand Down Expand Up @@ -258,7 +264,9 @@ def __init__(
birthday: "types.Birthday" = None,
personal_chat: "types.Chat" = None,
max_reaction_count: int = None,
subscription_until_date: datetime = None
subscription_until_date: datetime = None,
gifts_count: int = None,
bot_verification: "types.BotVerification" = None
):
super().__init__(client)

Expand Down Expand Up @@ -309,6 +317,8 @@ def __init__(
self.birthday = birthday
self.personal_chat = personal_chat
self.subscription_until_date = subscription_until_date
self.gifts_count = gifts_count
self.bot_verification = bot_verification

@property
def full_name(self) -> str:
Expand Down Expand Up @@ -450,9 +460,10 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
parsed_chat.bio = full_user.about
parsed_chat.folder_id = getattr(full_user, "folder_id", None)
parsed_chat.business_info = types.BusinessInfo._parse(client, full_user, users)
birthday = getattr(full_user, "birthday", None)
parsed_chat.birthday = types.Birthday._parse(birthday) if birthday is not None else None
parsed_chat.birthday = types.Birthday._parse(getattr(full_user, "birthday", None))
parsed_chat.gifts_count = getattr(full_user, "stargifts_count", None)
personal_chat_id = getattr(full_user, "personal_channel_id", None)

if personal_chat_id is not None:
personal_chat = await client.invoke(
raw.functions.channels.GetChannels(
Expand Down Expand Up @@ -548,6 +559,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
full_chat.available_reactions
)
parsed_chat.max_reaction_count = getattr(full_chat, "reactions_limit", 11)
parsed_chat.bot_verification = types.BotVerification._parse(client, getattr(full_chat, "bot_verification", None), users)

return parsed_chat

Expand Down

0 comments on commit d032c3a

Please sign in to comment.