From 6b79475be412872833d144d33365aa4c3b48a0ba Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Mon, 1 Apr 2024 23:44:28 +0300 Subject: [PATCH] Add birthday attribute to Chat class --- compiler/docs/compiler.py | 1 + pyrogram/types/user_and_chats/__init__.py | 2 + pyrogram/types/user_and_chats/birthday.py | 62 +++++++++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 8 ++- pyrogram/types/user_and_chats/user.py | 4 +- 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 pyrogram/types/user_and_chats/birthday.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 1b9e4b1b..81eed78c 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -423,6 +423,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 e64034a4..7bf9053c 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from .birthday import Birthday from .business_info import BusinessInfo from .business_message import BusinessMessage from .business_recipients import BusinessRecipients @@ -49,6 +50,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..6d54b4c5 --- /dev/null +++ b/pyrogram/types/user_and_chats/birthday.py @@ -0,0 +1,62 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from typing import Optional + +from pyrogram import raw +from ..object import Object + + +class Birthday(Object): + """Birthday information of a user. + + Parameters: + day (``int``): + Birthday day. + + month (``int``): + Birthday month. + + year (``int``, *optional*): + Birthday year. + """ + + def __init__( + self, + *, + day: int, + month: int, + year: int = None + + ): + self.day = day + self.month = month + self.year = year + + @staticmethod + def _parse( + birthday: "raw.types.Birthday" = None + ) -> Optional["Birthday"]: + if not birthday: + return + + return Birthday( + day=birthday.day, + month=birthday.month, + year=getattr(birthday, "year", None) + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4f1e13b8..58b0b501 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -174,6 +174,9 @@ class Chat(Object): business_info (:obj:`~pyrogram.types.BusinessInfo`, *optional*): Business information of a chat. + + birthday (:obj:`~pyrogram.types.Birthday`, *optional*): + Information about user birthday. """ def __init__( @@ -221,7 +224,8 @@ class Chat(Object): level: int = 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) @@ -267,6 +271,7 @@ class Chat(Object): self.reply_color = reply_color self.profile_color = profile_color self.business_info = business_info + self.birthday = birthday @staticmethod def _parse_user_chat(client, user: raw.types.User) -> "Chat": @@ -390,6 +395,7 @@ 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) + parsed_chat.birthday = types.Birthday._parse(getattr(full_user, "birthday", None)) if full_user.pinned_msg_id: parsed_chat.pinned_message = await client.get_messages( diff --git a/pyrogram/types/user_and_chats/user.py b/pyrogram/types/user_and_chats/user.py index 817481c0..9ff36af1 100644 --- a/pyrogram/types/user_and_chats/user.py +++ b/pyrogram/types/user_and_chats/user.py @@ -164,10 +164,10 @@ class User(Object, Update): ``user.mention("another name")`` for a custom name. To choose a different style ("html" or "md"/"markdown") use ``user.mention(style="md")``. - reply_color (:obj:`~pyrogram.types.ChatColor`, *optional*) + reply_color (:obj:`~pyrogram.types.ChatColor`, *optional*): Chat reply color. - profile_color (:obj:`~pyrogram.types.ChatColor`, *optional*) + profile_color (:obj:`~pyrogram.types.ChatColor`, *optional*): Chat profile color. """