From 7924f53b1d40c74b275a1ef5e24d3fc16c7b53ca Mon Sep 17 00:00:00 2001 From: Zaid _ Date: Mon, 10 Jun 2024 18:00:08 +0300 Subject: [PATCH 1/6] Add ChatBackground type --- pyrogram/types/user_and_chats/__init__.py | 2 + .../types/user_and_chats/chat_background.py | 113 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 pyrogram/types/user_and_chats/chat_background.py diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 83c215e26a..a20c2d1866 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -45,6 +45,7 @@ from .video_chat_scheduled import VideoChatScheduled from .video_chat_started import VideoChatStarted from .rtmp_url import RtmpUrl +from .chat_background import ChatBackground __all__ = [ "Birthdate", @@ -76,4 +77,5 @@ "VideoChatScheduled", "VideoChatStarted", "RtmpUrl", + "ChatBackground" ] diff --git a/pyrogram/types/user_and_chats/chat_background.py b/pyrogram/types/user_and_chats/chat_background.py new file mode 100644 index 0000000000..8aad7cd8fe --- /dev/null +++ b/pyrogram/types/user_and_chats/chat_background.py @@ -0,0 +1,113 @@ +# 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 +from typing import List + +import pyrogram +from pyrogram import raw, utils +from pyrogram import types +from pyrogram.file_id import ( + FileId, + FileType, + FileUniqueId, + FileUniqueType, + ThumbnailSource, +) +from ..object import Object + + +class ChatBackground(Object): + """Describes a background set for a specific chat. + + Parameters: + file_id (``str``): + Identifier for this file, which can be used to download the file. + + file_unique_id (``str``): + Unique identifier for this file, which is supposed to be the same over time and for different accounts. + Can't be used to download or reuse the file. + + file_size (``int``): + File size. + + date (:py:obj:`~datetime.datetime`): + Date the background was setted. + + slug (``str``): + Identifier of the background code. + You can combine it with `https://t.me/bg/{slug}` + to get link for this background. + + thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*): + Available thumbnails of this background. + + link (``str``, *property*): + Generate a link to this background code. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + file_id: str, + file_unique_id: str, + file_size: int, + date: datetime, + slug: str, + thumbs: List["types.Thumbnail"] = None, + ): + super().__init__(client) + + self.file_id = file_id + self.file_unique_id = file_unique_id + self.file_size = file_size + self.date = date + self.slug = slug + self.thumbs = thumbs + + @property + def link(self) -> str: + return f"https://t.me/bg/{self.slug}" + + @staticmethod + def _parse( + client, + wallpaper: "raw.types.Wallpaper", + ) -> "ChatBackground": + return ChatBackground( + file_id=FileId( + dc_id=wallpaper.document.dc_id, + file_reference=wallpaper.document.file_reference, + access_hash=wallpaper.document.access_hash, + file_type=FileType.BACKGROUND, + media_id=wallpaper.document.id, + volume_id=0, + local_id=0, + thumbnail_source=ThumbnailSource.THUMBNAIL, + thumbnail_file_type=FileType.PHOBACKGROUNDTO, + ).encode(), + file_unique_id=FileUniqueId( + file_unique_type=FileUniqueType.DOCUMENT, media_id=wallpaper.document.id + ), + file_size=wallpaper.document.size, + slug=wallpaper.slug, + date=utils.timestamp_to_datetime(wallpaper.document.date), + thumbs=types.Thumbnail._parse(client, wallpaper.document), + client=client, + ) From a6d8fbcd2358e62250080cd623d769593c5d6afb Mon Sep 17 00:00:00 2001 From: Zaid _ Date: Mon, 10 Jun 2024 18:01:40 +0300 Subject: [PATCH 2/6] fix unused param in Chat class --- pyrogram/types/user_and_chats/chat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 4f60a38615..385faa089a 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -326,6 +326,7 @@ def __init__( self.business_location = business_location self.business_opening_hours = business_opening_hours self.active_usernames = active_usernames + self.max_reaction_count = max_reaction_count self._raw = _raw @staticmethod From f4d5094449c92171aa9edb01b70ca71eeb5f9542 Mon Sep 17 00:00:00 2001 From: Zaid _ Date: Mon, 10 Jun 2024 18:15:17 +0300 Subject: [PATCH 3/6] Add background for Chat --- pyrogram/types/user_and_chats/chat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 385faa089a..1f19b4fc5b 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -92,6 +92,9 @@ class Chat(Object): emoji_status (:obj:`~pyrogram.types.EmojiStatus`, *optional*): Emoji status. + background (:obj:`~pyrogram.types.ChatBackground`, *optional*): + A chat background. + bio (``str``, *optional*): Bio of the other party in a private chat. Returned only in :meth:`~pyrogram.Client.get_chat`. @@ -254,6 +257,7 @@ def __init__( accent_color: "types.ChatColor" = None, profile_color: "types.ChatColor" = None, emoji_status: "types.EmojiStatus" = None, + background: "types.ChatBackground" = None, has_visible_history: bool = None, has_hidden_members: bool = None, has_aggressive_anti_spam_enabled: bool = None, @@ -308,6 +312,7 @@ def __init__( self.accent_color = accent_color self.profile_color = profile_color self.emoji_status = emoji_status + self.background = background self.has_visible_history = has_visible_history self.has_hidden_members = has_hidden_members self.has_aggressive_anti_spam_enabled = has_aggressive_anti_spam_enabled @@ -610,6 +615,9 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw. if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported): parsed_chat.invite_link = full_chat.exported_invite.link + if hasattr(full_chat, "wallpaper") and getattr(full_chat, "wallpaper"): + parsed_chat.background = types.ChatBackground._parse(client, full_chat.wallpaper) + parsed_chat.available_reactions = types.ChatReactions._parse( client, full_chat.available_reactions, From 2893039d8e59836b5861ccaf8aa2a37c0581ccb4 Mon Sep 17 00:00:00 2001 From: Zaid _ <162994967+zaid5o5@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:43:50 +0300 Subject: [PATCH 4/6] fix --- pyrogram/types/user_and_chats/chat_background.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat_background.py b/pyrogram/types/user_and_chats/chat_background.py index 8aad7cd8fe..3c3ef50d1d 100644 --- a/pyrogram/types/user_and_chats/chat_background.py +++ b/pyrogram/types/user_and_chats/chat_background.py @@ -100,7 +100,7 @@ def _parse( volume_id=0, local_id=0, thumbnail_source=ThumbnailSource.THUMBNAIL, - thumbnail_file_type=FileType.PHOBACKGROUNDTO, + thumbnail_file_type=FileType.BACKGROUND, ).encode(), file_unique_id=FileUniqueId( file_unique_type=FileUniqueType.DOCUMENT, media_id=wallpaper.document.id From 530afb4c4d8dc85e663d0eb42228894499d10509 Mon Sep 17 00:00:00 2001 From: Zaid _ <162994967+zaid5o5@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:49:15 +0300 Subject: [PATCH 5/6] fx --- pyrogram/types/user_and_chats/chat_background.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/types/user_and_chats/chat_background.py b/pyrogram/types/user_and_chats/chat_background.py index 3c3ef50d1d..a4b2d2ab54 100644 --- a/pyrogram/types/user_and_chats/chat_background.py +++ b/pyrogram/types/user_and_chats/chat_background.py @@ -104,7 +104,7 @@ def _parse( ).encode(), file_unique_id=FileUniqueId( file_unique_type=FileUniqueType.DOCUMENT, media_id=wallpaper.document.id - ), + ).encode(), file_size=wallpaper.document.size, slug=wallpaper.slug, date=utils.timestamp_to_datetime(wallpaper.document.date), From 25a7cba717c4d82be3b592018366528a348e6bbc Mon Sep 17 00:00:00 2001 From: Shrimadhav U K Date: Mon, 10 Jun 2024 21:30:47 +0530 Subject: [PATCH 6/6] Update compiler.py --- compiler/docs/compiler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 59a1e19fb7..6793352622 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -616,6 +616,7 @@ def get_title_list(s: str) -> list: VideoChatScheduled VideoChatStarted RtmpUrl + ChatBackground """, )