-
-
Notifications
You must be signed in to change notification settings - Fork 49
Add ChatBackground type and fix. #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a89f95b
add ChatBackground
z44d f07a23f
add .background field
z44d eec5ec8
fix type hint
z44d c2802f9
update docs
z44d 4fe419c
reformat
z44d b3382e9
update copyright and import
z44d 3c773f9
chore: enable `annotations` future import and lint
alissonlauffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
add ChatBackground
- Loading branch information
commit a89f95b7697b8c18a0871168dadfe5373bd4b500
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # 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/>. | ||
|
alissonlauffer marked this conversation as resolved.
Outdated
|
||
|
|
||
| from datetime import datetime | ||
| from typing import List | ||
|
|
||
| import hydrogram | ||
| from hydrogram import raw, utils | ||
| from hydrogram import types | ||
| from hydrogram.file_id import ( | ||
| FileId, | ||
| FileType, | ||
| FileUniqueId, | ||
| FileUniqueType, | ||
| ThumbnailSource, | ||
| ) | ||
| from ..object import Object | ||
|
alissonlauffer marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| 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: "hydrogram.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.BACKGROUND, | ||
| ).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), | ||
| thumbs=types.Thumbnail._parse(client, wallpaper.document), | ||
| client=client, | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.