Skip to content

Commit

Permalink
Added the classes BusinessOpeningHours and BusinessOpeningHoursInterv…
Browse files Browse the repository at this point in the history
…al and the field business_opening_hours to the class Chat.
  • Loading branch information
SpEcHiDe committed Apr 13, 2024
1 parent 1cbe42f commit 19436a9
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ def get_title_list(s: str) -> list:
BusinessConnection
BusinessIntro
BusinessLocation
BusinessOpeningHours
BusinessOpeningHoursInterval
""",
)

Expand Down
1 change: 1 addition & 0 deletions docs/source/releases/changes-in-this-fork.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions pyrogram/types/business/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
69 changes: 69 additions & 0 deletions pyrogram/types/business/business_opening_hours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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 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
)
58 changes: 58 additions & 0 deletions pyrogram/types/business/business_opening_hours_interval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 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
)
11 changes: 11 additions & 0 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 19436a9

Please sign in to comment.