Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
pyrogram/pyrogram/types/messages_and_media/sticker.py at master · ndtcoder/pyrogram · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
ndtcoder
/
pyrogram
Public
forked from
pyrogram/pyrogram
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
pyrogram
/
pyrogram
/
types
/
messages_and_media
/
sticker.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
206 lines (173 loc) · 6.75 KB
master
Breadcrumbs
pyrogram
/
pyrogram
/
types
/
messages_and_media
/
sticker.py
Copy path
Top
File metadata and controls
Code
Blame
206 lines (173 loc) · 6.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# 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
from
typing
import
List
,
Dict
,
Type
import
pyrogram
from
pyrogram
import
raw
,
utils
from
pyrogram
import
types
from
pyrogram
.
errors
import
StickersetInvalid
from
pyrogram
.
file_id
import
FileId
,
FileType
,
FileUniqueId
,
FileUniqueType
from
..
object
import
Object
class
Sticker
(
Object
):
"""A sticker.
Parameters:
file_id (``str``):
Identifier for this file, which can be used to download or reuse 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.
width (``int``):
Sticker width.
height (``int``):
Sticker height.
is_animated (``bool``):
True, if the sticker is animated
is_video (``bool``):
True, if the sticker is a video sticker
file_name (``str``, *optional*):
Sticker file name.
mime_type (``str``, *optional*):
MIME type of the file as defined by sender.
file_size (``int``, *optional*):
File size.
date (:py:obj:`~datetime.datetime`, *optional*):
Date the sticker was sent.
emoji (``str``, *optional*):
Emoji associated with the sticker.
set_name (``str``, *optional*):
Name of the sticker set to which the sticker belongs.
thumbs (List of :obj:`~pyrogram.types.Thumbnail`, *optional*):
Sticker thumbnails in the .webp or .jpg format.
"""
# TODO: Add mask position
def
__init__
(
self
,
*
,
client
:
"pyrogram.Client"
=
None
,
file_id
:
str
,
file_unique_id
:
str
,
width
:
int
,
height
:
int
,
is_animated
:
bool
,
is_video
:
bool
,
file_name
:
str
=
None
,
mime_type
:
str
=
None
,
file_size
:
int
=
None
,
date
:
datetime
=
None
,
emoji
:
str
=
None
,
set_name
:
str
=
None
,
thumbs
:
List
[
"types.Thumbnail"
]
=
None
):
super
().
__init__
(
client
)
self
.
file_id
=
file_id
self
.
file_unique_id
=
file_unique_id
self
.
file_name
=
file_name
self
.
mime_type
=
mime_type
self
.
file_size
=
file_size
self
.
date
=
date
self
.
width
=
width
self
.
height
=
height
self
.
is_animated
=
is_animated
self
.
is_video
=
is_video
self
.
emoji
=
emoji
self
.
set_name
=
set_name
self
.
thumbs
=
thumbs
# self.mask_position = mask_position
cache
=
{}
@
staticmethod
async
def
_get_sticker_set_name
(
invoke
,
input_sticker_set_id
):
try
:
set_id
=
input_sticker_set_id
[
0
]
set_access_hash
=
input_sticker_set_id
[
1
]
name
=
Sticker
.
cache
.
get
((
set_id
,
set_access_hash
),
None
)
if
name
is
not
None
:
return
name
name
=
(
await
invoke
(
raw
.
functions
.
messages
.
GetStickerSet
(
stickerset
=
raw
.
types
.
InputStickerSetID
(
id
=
set_id
,
access_hash
=
set_access_hash
),
hash
=
0
)
)).
set
.
short_name
Sticker
.
cache
[(
set_id
,
set_access_hash
)]
=
name
if
len
(
Sticker
.
cache
)
>
250
:
for
i
in
range
(
50
):
Sticker
.
cache
.
pop
(
next
(
iter
(
Sticker
.
cache
)))
return
name
except
StickersetInvalid
:
return
None
@
staticmethod
async
def
_parse
(
client
,
sticker
:
"raw.types.Document"
,
document_attributes
:
Dict
[
Type
[
"raw.base.DocumentAttribute"
],
"raw.base.DocumentAttribute"
],
)
->
"Sticker"
:
sticker_attributes
=
(
document_attributes
[
raw
.
types
.
DocumentAttributeSticker
]
if
raw
.
types
.
DocumentAttributeSticker
in
document_attributes
else
document_attributes
[
raw
.
types
.
DocumentAttributeCustomEmoji
]
)
image_size_attributes
=
document_attributes
.
get
(
raw
.
types
.
DocumentAttributeImageSize
,
None
)
file_name
=
getattr
(
document_attributes
.
get
(
raw
.
types
.
DocumentAttributeFilename
,
None
),
"file_name"
,
None
)
video_attributes
=
document_attributes
.
get
(
raw
.
types
.
DocumentAttributeVideo
,
None
)
sticker_set
=
sticker_attributes
.
stickerset
if
isinstance
(
sticker_set
,
raw
.
types
.
InputStickerSetID
):
input_sticker_set_id
=
(
sticker_set
.
id
,
sticker_set
.
access_hash
)
set_name
=
await
Sticker
.
_get_sticker_set_name
(
client
.
invoke
,
input_sticker_set_id
)
else
:
set_name
=
None
return
Sticker
(
file_id
=
FileId
(
file_type
=
FileType
.
STICKER
,
dc_id
=
sticker
.
dc_id
,
media_id
=
sticker
.
id
,
access_hash
=
sticker
.
access_hash
,
file_reference
=
sticker
.
file_reference
).
encode
(),
file_unique_id
=
FileUniqueId
(
file_unique_type
=
FileUniqueType
.
DOCUMENT
,
media_id
=
sticker
.
id
).
encode
(),
width
=
(
image_size_attributes
.
w
if
image_size_attributes
else
video_attributes
.
w
if
video_attributes
else
512
),
height
=
(
image_size_attributes
.
h
if
image_size_attributes
else
video_attributes
.
h
if
video_attributes
else
512
),
is_animated
=
sticker
.
mime_type
==
"application/x-tgsticker"
,
is_video
=
sticker
.
mime_type
==
"video/webm"
,
# TODO: mask_position
set_name
=
set_name
,
emoji
=
sticker_attributes
.
alt
or
None
,
file_size
=
sticker
.
size
,
mime_type
=
sticker
.
mime_type
,
file_name
=
file_name
,
date
=
utils
.
timestamp_to_datetime
(
sticker
.
date
),
thumbs
=
types
.
Thumbnail
.
_parse
(
client
,
sticker
),
client
=
client
)
You can’t perform that action at this time.