diff --git a/src/lib/utils.js b/src/lib/utils.js index bd9d9d7..1826263 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -33,17 +33,19 @@ function safeString(string, newLines = true) { function formatTime(number) { let seconds = parseInt(number) / 1000; - const days = seconds / 86400; + const days = Math.floor(seconds / 86400); seconds = seconds % 86400; - const hours = seconds / 3600; + const hours = Math.floor(seconds / 3600); seconds = seconds % 3600; - const minutes = seconds / 60; - seconds = seconds % 60; + const minutes = Math.floor(seconds / 60); + seconds = Math.floor(seconds % 60); return ( - (days !== 0 ? `${days.padStart(2, "0")}:` : "") + - (hours !== 0 ? `${hours.padStart(2, "0")}:` : "") + - `${minutes.padStart(2, "0")}:${seconds.padStart(2, "0")}` + (days !== 0 ? `${days.toString().padStart(2, "0")}:` : "") + + (hours !== 0 ? `${hours.toString().padStart(2, "0")}:` : "") + + `${minutes.toString().padStart(2, "0")}:${seconds + .toString() + .padStart(2, "0")}` ); } @@ -100,6 +102,25 @@ async function findLastImage(msg, gif = false) { const urlRegex = /((https?):\/)?\/?([^:/\s]+)((\/\w+)*\/)([\w\-.]+)/; async function getImage(msg, str) { + const refMsg = msg.referencedMessage; + if (refMsg) { + if (refMsg.attachments[0] && refMsg.attachments[0].url) { + return refMsg.attachments[0].url; + } else if (//.test(refMsg.content)) { + const id = refMsg.content.match(//)[1]; + return `https://cdn.discordapp.com/emojis/${id}.png?v=1`; + } else if (/<@!?([0-9]*)>/.test(refMsg.content)) { + const id = refMsg.content.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`; + } + } + const img = await findLastImage(msg, false); if (!str) { if (img) return img;