Add birthday attribute to Chat class

This commit is contained in:
KurimuzonAkuma 2024-04-01 23:44:28 +03:00
parent 68ffa1ffc2
commit 6b79475be4
5 changed files with 74 additions and 3 deletions

View File

@ -423,6 +423,7 @@ def pyrogram_api():
categories = dict(
users_chats="""
Users & Chats
Birthday
BusinessInfo
BusinessMessage
BusinessRecipients

View File

@ -16,6 +16,7 @@
# 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 .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",

View File

@ -0,0 +1,62 @@
# 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
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)
)

View File

@ -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(

View File

@ -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.
"""