Pyrofork: Add birthday field to class Chat

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2024-04-05 19:00:34 +07:00
parent f326333acf
commit 85892c23d0
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
4 changed files with 68 additions and 1 deletions

View file

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

View file

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

View file

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

View file

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