From 85892c23d0771b8e34b2dd5eb0605f916bf9aa80 Mon Sep 17 00:00:00 2001 From: wulan17 Date: Fri, 5 Apr 2024 19:00:34 +0700 Subject: [PATCH] Pyrofork: Add birthday field to class Chat Signed-off-by: wulan17 --- compiler/docs/compiler.py | 1 + pyrogram/types/user_and_chats/__init__.py | 2 + pyrogram/types/user_and_chats/birthday.py | 57 +++++++++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 9 +++- 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 pyrogram/types/user_and_chats/birthday.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 61de1aa6..d2379e48 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -421,6 +421,7 @@ def pyrogram_api(): categories = dict( users_chats=""" Users & Chats + Birthday BusinessInfo BusinessMessage BusinessRecipients diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 474527d6..cc286983 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrofork. If not, see . +from .birthday import Birthday from .business_info import BusinessInfo from .business_message import BusinessMessage from .business_recipients import BusinessRecipients @@ -59,6 +60,7 @@ from .video_chat_scheduled import VideoChatScheduled from .video_chat_started import VideoChatStarted __all__ = [ + "Birthday", "BusinessInfo", "BusinessMessage", "BusinessRecipients", diff --git a/pyrogram/types/user_and_chats/birthday.py b/pyrogram/types/user_and_chats/birthday.py new file mode 100644 index 00000000..7c5d83ed --- /dev/null +++ b/pyrogram/types/user_and_chats/birthday.py @@ -0,0 +1,57 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2022-present 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 . + +from typing import Optional, Union + +from pyrogram import raw +from pyrogram import enums +from ..object import Object + + +class Birthday(Object): + """User Date of birth. + + Parameters: + day (``int``): + Day of birth. + + month (``int``): + Month of birth. + + year (``int``): + Year of birth. + """ + + def __init__( + self, + *, + day: int, + month: int, + year: int + ): + self.day = day + self.month = month + self.year = year + + @staticmethod + def _parse(birthday: "raw.types.Birthday" = None) -> "Birthday": + return Birthday( + day=birthday.day, + month=birthday.month, + year=birthday.year + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 66ac6371..ffe94901 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -183,6 +183,9 @@ class Chat(Object): business_info (:obj:`~pyrogram.types.BusinessInfo`, *optional*): Business information of a chat. + + birthday (:obj:`~pyrogram.types.Birthday`, *optional*): + User Date of birth. """ def __init__( @@ -230,7 +233,8 @@ class Chat(Object): usernames: List["types.Username"] = None, reply_color: "types.ChatColor" = None, profile_color: "types.ChatColor" = None, - business_info: "types.BusinessInfo" = None + business_info: "types.BusinessInfo" = None, + birthday: "types.Birthday" = None ): super().__init__(client) @@ -276,6 +280,7 @@ class Chat(Object): self.reply_color = reply_color self.profile_color = profile_color self.business_info = business_info + self.birthday = birthday @property def full_name(self) -> str: @@ -413,6 +418,8 @@ class Chat(Object): 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 if full_user.pinned_msg_id: parsed_chat.pinned_message = await client.get_messages(