|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from datetime import datetime |
| 20 | +from typing import List |
| 21 | + |
| 22 | +import pyrogram |
| 23 | +from pyrogram import raw, utils |
| 24 | +from pyrogram import types |
| 25 | +from pyrogram.file_id import ( |
| 26 | + FileId, |
| 27 | + FileType, |
| 28 | + FileUniqueId, |
| 29 | + FileUniqueType, |
| 30 | + ThumbnailSource, |
| 31 | +) |
| 32 | +from ..object import Object |
| 33 | + |
| 34 | + |
| 35 | +class ChatBackground(Object): |
| 36 | + """Describes a background set for a specific chat. |
| 37 | +
|
| 38 | + Parameters: |
| 39 | + file_id (``str``): |
| 40 | + Identifier for this file, which can be used to download the file. |
| 41 | +
|
| 42 | + file_unique_id (``str``): |
| 43 | + Unique identifier for this file, which is supposed to be the same over time and for different accounts. |
| 44 | + Can't be used to download or reuse the file. |
| 45 | +
|
| 46 | + file_size (``int``): |
| 47 | + File size. |
| 48 | +
|
| 49 | + date (:py:obj:`~datetime.datetime`): |
| 50 | + Date the background was setted. |
| 51 | +
|
| 52 | + slug (``str``): |
| 53 | + Identifier of the background code. |
| 54 | + You can combine it with `https://t.me/bg/{slug}` |
| 55 | + to get link for this background. |
| 56 | +
|
| 57 | + thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*): |
| 58 | + Available thumbnails of this background. |
| 59 | +
|
| 60 | + link (``str``, *property*): |
| 61 | + Generate a link to this background code. |
| 62 | + """ |
| 63 | + |
| 64 | + def __init__( |
| 65 | + self, |
| 66 | + *, |
| 67 | + client: "pyrogram.Client" = None, |
| 68 | + file_id: str, |
| 69 | + file_unique_id: str, |
| 70 | + file_size: int, |
| 71 | + date: datetime, |
| 72 | + slug: str, |
| 73 | + thumbs: List["types.Thumbnail"] = None, |
| 74 | + ): |
| 75 | + super().__init__(client) |
| 76 | + |
| 77 | + self.file_id = file_id |
| 78 | + self.file_unique_id = file_unique_id |
| 79 | + self.file_size = file_size |
| 80 | + self.date = date |
| 81 | + self.slug = slug |
| 82 | + self.thumbs = thumbs |
| 83 | + |
| 84 | + @property |
| 85 | + def link(self) -> str: |
| 86 | + return f"https://t.me/bg/{self.slug}" |
| 87 | + |
| 88 | + @staticmethod |
| 89 | + def _parse( |
| 90 | + client, |
| 91 | + wallpaper: "raw.types.Wallpaper", |
| 92 | + ) -> "ChatBackground": |
| 93 | + return ChatBackground( |
| 94 | + file_id=FileId( |
| 95 | + dc_id=wallpaper.document.dc_id, |
| 96 | + file_reference=wallpaper.document.file_reference, |
| 97 | + access_hash=wallpaper.document.access_hash, |
| 98 | + file_type=FileType.BACKGROUND, |
| 99 | + media_id=wallpaper.document.id, |
| 100 | + volume_id=0, |
| 101 | + local_id=0, |
| 102 | + thumbnail_source=ThumbnailSource.THUMBNAIL, |
| 103 | + thumbnail_file_type=FileType.BACKGROUND, |
| 104 | + ).encode(), |
| 105 | + file_unique_id=FileUniqueId( |
| 106 | + file_unique_type=FileUniqueType.DOCUMENT, media_id=wallpaper.document.id |
| 107 | + ).encode(), |
| 108 | + file_size=wallpaper.document.size, |
| 109 | + slug=wallpaper.slug, |
| 110 | + date=utils.timestamp_to_datetime(wallpaper.document.date), |
| 111 | + thumbs=types.Thumbnail._parse(client, wallpaper.document), |
| 112 | + client=client, |
| 113 | + ) |
0 commit comments