My main goal is to be able to run a small command like, $yoink
, that will take the last sent emoji in the chat and make it into an image I can download. I've already got something like this but, it only detects regular images and embedded images (using it to make Jimp function with my bot)
Here's what I have so far:
async function GetImageFromMsg(msg) {
var imageUrl = null;
const urlsnifferpattern = /(https?:\/\/[^\s]+\.(?:png|jpg|jpeg|bmp|gif|tiff|webp)(?:$|[^\s]+))/i;
if (msg.attachments && (getImg = msg.attachments.find(val => val.height && val.url)) && getImg.url.match(urlsnifferpattern)) // user uploads directly to chat.
imageUrl = getImg.url;
if (msg.content && (getImg = msg.content.match(urlsnifferpattern))) // Here first to avoid caching issues on the next two checks.
imageUrl = getImg[0].replace(">", "");
if (msg.embeds && (getImg = msg.embeds.find(val => val.thumbnail && val.thumbnail.url))) // small image ONLY on bot-made embeds - (small??>)big image on LINK-made embeds - random image URLS with no embeds.
imageUrl = getImg.thumbnail.url;
if (msg.embeds && (getImg = msg.embeds.find(val => val.image && val.image.url))) // big image on bot-made embeds.
imageUrl = getImg.image.url;
if (!imageUrl)
return null;
return imageUrl;
}
How should I go about adding in support to also grab emoji?