From 19436a9bb2984373ad112f72b1f5e2e71ecc99d2 Mon Sep 17 00:00:00 2001 From: shriMADhav U k Date: Sat, 13 Apr 2024 21:03:46 +0200 Subject: [PATCH] Added the classes BusinessOpeningHours and BusinessOpeningHoursInterval and the field business_opening_hours to the class Chat. --- compiler/docs/compiler.py | 2 + docs/source/releases/changes-in-this-fork.rst | 1 + pyrogram/types/business/__init__.py | 4 ++ .../types/business/business_opening_hours.py | 69 +++++++++++++++++++ .../business_opening_hours_interval.py | 58 ++++++++++++++++ pyrogram/types/user_and_chats/chat.py | 11 +++ 6 files changed, 145 insertions(+) create mode 100644 pyrogram/types/business/business_opening_hours.py create mode 100644 pyrogram/types/business/business_opening_hours_interval.py diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 0f9aa7454..0233f8c16 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -550,6 +550,8 @@ def get_title_list(s: str) -> list: BusinessConnection BusinessIntro BusinessLocation + BusinessOpeningHours + BusinessOpeningHoursInterval """, ) diff --git a/docs/source/releases/changes-in-this-fork.rst b/docs/source/releases/changes-in-this-fork.rst index db4b400a9..1fad76289 100644 --- a/docs/source/releases/changes-in-this-fork.rst +++ b/docs/source/releases/changes-in-this-fork.rst @@ -12,6 +12,7 @@ it can take advantage of new goodies! | Scheme layer used: 177 | +------------------------+ +- Added the classes :obj:`~pyrogram.types.BusinessOpeningHours` and :obj:`~pyrogram.types.BusinessOpeningHoursInterval` and the field ``business_opening_hours`` to the class :obj:`~pyrogram.types.Chat`. - Added the class :obj:`~pyrogram.types.BusinessLocation` and the field ``business_location`` to the class :obj:`~pyrogram.types.Chat`. - Added the class :obj:`~pyrogram.types.BusinessIntro` and the field ``business_intro`` to the class :obj:`~pyrogram.types.Chat`. - Added the parameter ``business_connection_id`` to the methods :meth:`~pyrogram.Client.send_message`, :meth:`~pyrogram.Client.send_photo`, :meth:`~pyrogram.Client.send_video`, :meth:`~pyrogram.Client.send_animation`, :meth:`~pyrogram.Client.send_audio`, :meth:`~pyrogram.Client.send_document`, :meth:`~pyrogram.Client.send_sticker`, :meth:`~pyrogram.Client.send_video_note`, :meth:`~pyrogram.Client.send_voice`, :meth:`~pyrogram.Client.send_location`, :meth:`~pyrogram.Client.send_venue`, :meth:`~pyrogram.Client.send_contact`, :meth:`~pyrogram.Client.send_poll`, :meth:`~pyrogram.Client.send_game`, :meth:`~pyrogram.Client.send_media_group`, :meth:`~pyrogram.Client.send_dice`, :meth:`~pyrogram.Client.send_chat_action`, :meth:`~pyrogram.Client.send_cached_media` and :meth:`~pyrogram.Client.copy_message` and the corresponding reply_* methods. diff --git a/pyrogram/types/business/__init__.py b/pyrogram/types/business/__init__.py index 42d4a0255..1ff4c9353 100644 --- a/pyrogram/types/business/__init__.py +++ b/pyrogram/types/business/__init__.py @@ -19,9 +19,13 @@ from .business_connection import BusinessConnection from .business_intro import BusinessIntro from .business_location import BusinessLocation +from .business_opening_hours import BusinessOpeningHours +from .business_opening_hours_interval import BusinessOpeningHoursInterval __all__ = [ "BusinessConnection", "BusinessIntro", "BusinessLocation", + "BusinessOpeningHours", + "BusinessOpeningHoursInterval", ] diff --git a/pyrogram/types/business/business_opening_hours.py b/pyrogram/types/business/business_opening_hours.py new file mode 100644 index 000000000..245a21b7f --- /dev/null +++ b/pyrogram/types/business/business_opening_hours.py @@ -0,0 +1,69 @@ +# 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 List +from datetime import datetime + +import pyrogram +from pyrogram import raw, types, utils + +from ..object import Object + + +class BusinessOpeningHours(Object): + """ + + Parameters: + time_zone_name (``str``): + Unique name of the time zone for which the opening hours are defined + + opening_hours (List of :obj:`~pyrogram.types.BusinessOpeningHoursInterval`): + List of time intervals describing business opening hours + + """ + + def __init__( + self, + *, + time_zone_name: str = None, + opening_hours: List["types.BusinessOpeningHoursInterval"] = None, + _raw: "raw.types.BusinessWorkHours" = None + ): + super().__init__() + + self.time_zone_name = time_zone_name + self.opening_hours = opening_hours + self._raw = _raw + + + @staticmethod + def _parse( + client, + business_work_hours: "raw.types.BusinessWorkHours" + ) -> "BusinessOpeningHours": + return BusinessOpeningHours( + time_zone_name=getattr(business_work_hours, "timezone_id", None), + opening_hours=types.List( + [ + types.BusinessOpeningHoursInterval._parse( + weekly_open_ + ) for weekly_open_ in business_work_hours.weekly_open + ] + ) if getattr(business_work_hours, "weekly_open", None) else None, + _raw=business_work_hours + ) diff --git a/pyrogram/types/business/business_opening_hours_interval.py b/pyrogram/types/business/business_opening_hours_interval.py new file mode 100644 index 000000000..e8ff568ed --- /dev/null +++ b/pyrogram/types/business/business_opening_hours_interval.py @@ -0,0 +1,58 @@ +# 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 datetime import datetime + +import pyrogram +from pyrogram import raw, types, utils + +from ..object import Object + + +class BusinessOpeningHoursInterval(Object): + """ + + Parameters: + opening_minute (``int``): + The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60 + + closing_minute (``int``): + The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 + + """ + + def __init__( + self, + *, + opening_minute: int = None, + closing_minute: int = None + ): + super().__init__() + + self.opening_minute = opening_minute + self.closing_minute = closing_minute + + + @staticmethod + def _parse( + weekly_open_: "raw.types.BusinessWeeklyOpen" + ) -> "BusinessOpeningHoursInterval": + return BusinessOpeningHoursInterval( + opening_minute=weekly_open_.start_minute, + closing_minute=weekly_open_.end_minute + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index ce563bf98..fe241916e 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -67,6 +67,9 @@ class Chat(Object): business_location (:obj:`~pyrogram.types.BusinessLocation`, *optional*): For private chats with business accounts, the location of the business. + business_opening_hours (:obj:`~pyrogram.types.BusinessOpeningHours`, *optional*): + For private chats with business accounts, the opening hours of the business. + personal_chat (:obj:`~pyrogram.types.Chat`, *optional*): For private chats, the personal channel of the user. @@ -211,6 +214,7 @@ def __init__( birthdate: "types.Birthdate" = None, business_intro: "types.BusinessIntro" = None, business_location: "types.BusinessLocation" = None, + business_opening_hours: "types.BusinessOpeningHours" = None, bio: str = None, join_by_request: bool = None, description: str = None, @@ -297,6 +301,7 @@ def __init__( self.birthdate = birthdate self.business_intro = business_intro self.business_location = business_location + self.business_opening_hours = business_opening_hours self.active_usernames = active_usernames self._raw = _raw @@ -488,6 +493,12 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw. client, full_user.business_location ) + if getattr(full_user, "business_work_hours", None): + parsed_chat.business_opening_hours = types.BusinessOpeningHours._parse( + client, + full_user.business_work_hours + ) + else: full_chat = chat_full.full_chat chat_raw = chats[full_chat.id]