lib.utils: add reply support to getImage
This commit is contained in:
parent
aa3f47188c
commit
4b8172ff71
|
@ -33,17 +33,19 @@ function safeString(string, newLines = true) {
|
||||||
|
|
||||||
function formatTime(number) {
|
function formatTime(number) {
|
||||||
let seconds = parseInt(number) / 1000;
|
let seconds = parseInt(number) / 1000;
|
||||||
const days = seconds / 86400;
|
const days = Math.floor(seconds / 86400);
|
||||||
seconds = seconds % 86400;
|
seconds = seconds % 86400;
|
||||||
const hours = seconds / 3600;
|
const hours = Math.floor(seconds / 3600);
|
||||||
seconds = seconds % 3600;
|
seconds = seconds % 3600;
|
||||||
const minutes = seconds / 60;
|
const minutes = Math.floor(seconds / 60);
|
||||||
seconds = seconds % 60;
|
seconds = Math.floor(seconds % 60);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(days !== 0 ? `${days.padStart(2, "0")}:` : "") +
|
(days !== 0 ? `${days.toString().padStart(2, "0")}:` : "") +
|
||||||
(hours !== 0 ? `${hours.padStart(2, "0")}:` : "") +
|
(hours !== 0 ? `${hours.toString().padStart(2, "0")}:` : "") +
|
||||||
`${minutes.padStart(2, "0")}:${seconds.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\-.]+)/;
|
const urlRegex = /((https?):\/)?\/?([^:/\s]+)((\/\w+)*\/)([\w\-.]+)/;
|
||||||
|
|
||||||
async function getImage(msg, str) {
|
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 (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(refMsg.content)) {
|
||||||
|
const id = refMsg.content.match(/<a?:[a-zA-Z0-9_]*:([0-9]*)>/)[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);
|
const img = await findLastImage(msg, false);
|
||||||
if (!str) {
|
if (!str) {
|
||||||
if (img) return img;
|
if (img) return img;
|
||||||
|
|
Loading…
Reference in New Issue