steal media now only steals gifs

This commit is contained in:
david committed 2026-10-20 14:47:03 -03:00
1 parent 7c1fbbcf5b
commit 7958daa50d
1 file changed
+5 -4
+5 -4
View File
@@ -287,17 +287,18 @@ async def steal_media(url: str, name: str):
f.write(f"[{now_str()}] saved media: {name}\n")
async def steal_attachments(message):
#steal images and gifs and stuff (always do this regardless of what else fires)
#steal gifs only (always do this regardless of what else fires)
media = [
(a.url, f"{a.id}_{Path(a.filename).name}") for a in message.attachments
if a.content_type and a.content_type.startswith(("image/", "video/")) and a.size <= MEDIA_SAVE_MAX_BYTES
if a.content_type and a.content_type.split(";")[0].strip().lower() == "image/gif" and a.size <= MEDIA_SAVE_MAX_BYTES
]
for embed in message.embeds:
#tenor/klipy links come as gifv embeds with an mp4 in embed.video direct gif links are plain image embeds
for part in (embed.image, embed.video):
if part and part.url:
ext = Path(urlparse(part.url).path).suffix # no extension, no preview on discord, not worth keeping
if ext:
ext = Path(urlparse(part.url).path).suffix # no extension no preview on discord not worth keeping
if ext and (embed.type == "gifv" or ext.lower() == ".gif"):
media.append((part.url, hashlib.sha1(part.url.encode()).hexdigest()[:16] + ext))
for url, name in media: