diff --git a/src/lib/utils.js b/src/lib/utils.js
index 2ec0d90..225fb4e 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -96,6 +96,37 @@ async function findLastImage(msg, gif = false) {
});
}
+const urlRegex = /((https?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+)/;
+
+async function getImage(msg, str) {
+ const img = await findLastImage(msg, false);
+ if (!str) {
+ if (img) return img;
+ }
+
+ if (msg.attachments[0] && msg.attachments[0].url) {
+ return msg.attachments[0].url;
+ } else if (urlRegex.test(str)) {
+ return str;
+ } else if (//.test(str)) {
+ const id = str.match(//)[1];
+ return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
+ } else if (/<@!?([0-9]*)>/.test(str)) {
+ const id = url.match(/<@?!([0-9]*)>/)[1];
+ const user = await hf.bot.requestHandler.request(
+ "GET",
+ "/users/" + id,
+ true
+ );
+ if (user)
+ return `https://cdn.discordapp.com/avatars/${id}/${user.avatar}.png?size=1024`;
+ } else if (img) {
+ return img;
+ }
+
+ return null;
+}
+
async function hastebin(body) {
const res = await fetch(`${hf.config.haste_provider}/documents`, {
method: "POST",
@@ -112,5 +143,6 @@ module.exports = {
readableTime,
isGif,
findLastImage,
+ getImage,
hastebin,
};