From 4e3e420875a4676153211a1b430b2087995f1fc8 Mon Sep 17 00:00:00 2001 From: Essem Date: Fri, 26 Aug 2022 14:54:26 -0500 Subject: [PATCH] Fix case-insensitive gfycat links in slash commands --- utils/imagedetect.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/imagedetect.js b/utils/imagedetect.js index 87534c4..15d87f9 100644 --- a/utils/imagedetect.js +++ b/utils/imagedetect.js @@ -75,7 +75,14 @@ const getImage = async (image, image2, video, extraReturnTypes, gifv = false, ty payload.path = image.replace(".mp4", ".gif"); } else if (gfycatURLs.includes(host)) { // iirc Gfycat also seems to sometimes make GIFs static - payload.path = `https://thumbs.gfycat.com/${image.split("/").pop().split(".mp4")[0]}-size_restricted.gif`; + if (link) { + const data = await request(`https://api.gfycat.com/v1/gfycats/${image.split("/").pop().split(".mp4")[0]}`); + const json = await data.body.json(); + if (json.errorMessage) throw Error(json.errorMessage); + payload.path = json.gfyItem.gifUrl; + } else { + payload.path = `https://thumbs.gfycat.com/${image.split("/").pop().split(".mp4")[0]}-size_restricted.gif`; + } } payload.type = "image/gif"; } else if (video) {