Skip to content

Commit 4ecc675

Browse files
add support for gif stickers
1 parent 071146e commit 4ecc675

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

libs/rlottie

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 36ddb42d78d1b13c1b1d7e1699aef8a9f339ab6f

python/caching.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def cached_path(cache: Path | str, id, type: ImageType, format: str | None = Non
5656
# and one non-static format: gif (also taken from there)
5757
# BUT it seems like avatar decorations can be .apng (Animated PNG, sometimes extension is .png)
5858
# upd on APNG: seems like anything can be it and it's just png in original quality, besides (and if!) being animated
59+
# upd2: so also there is lottie for stickers...
5960

6061
def construct_qml_data(path, url=None, animated=None, extension=None):
6162
if animated is None:
@@ -136,13 +137,13 @@ def has_cached_session(self, id, type: ImageType, finished=None):
136137
else:
137138
return True
138139

139-
def easy(self, url, id, type: ImageType, format: str|None=None, as_qml_data=True):
140+
def easy(self, url, id, type: ImageType, format: str|None=None, as_qml_data=True, animated=None):
140141
icon = '' if url is None else \
141142
str(self.get_cached_path(id, type, url, format))
142143
if icon != '':
143144
self.cache_image_bg(str(url), id, type, format)
144145
if as_qml_data:
145146
if icon == '':
146147
return STUB_QML_ASSET
147-
return construct_qml_data(icon, url)
148+
return construct_qml_data(icon, url, animated)
148149
return icon

python/sending.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import discord
1212

1313

14-
SUPPORTED_STICKER_FORMATS = (discord.StickerFormatType.png,)
14+
SUPPORTED_ANIMATED_STICKER_FORMATS = {discord.StickerFormatType.gif}#, discord.StickerFormatType.lottie}
15+
SUPPORTED_STICKER_FORMATS = SUPPORTED_ANIMATED_STICKER_FORMATS | {discord.StickerFormatType.png}
1516

1617
# Servers
1718

@@ -124,7 +125,8 @@ def convert_attachments(attachments: list[discord.Attachment]):
124125
return res
125126

126127
def generate_stickers(stickers: list[discord.StickerItem], cacher: Cacher):
127-
return [cacher.easy(s.url, s.id, ImageType.STICKER) for s in stickers if s.format in SUPPORTED_STICKER_FORMATS]
128+
return [cacher.easy(s.url, s.id, ImageType.STICKER, animated = s.format in SUPPORTED_ANIMATED_STICKER_FORMATS)
129+
for s in stickers if s.format in SUPPORTED_STICKER_FORMATS]
128130

129131

130132
def generate_extra_message(message: discord.Message | discord.MessageSnapshot, cacher: Cacher | None = None, emoji_size: Any | None = None, ref={}):

0 commit comments

Comments
 (0)