utils: fix getImage and findLastImage
This commit is contained in:
parent
177b5d6534
commit
4af91ad249
1 changed files with 8 additions and 6 deletions
|
@ -79,8 +79,8 @@ async function findLastImage(msg, gif = false) {
|
||||||
let img;
|
let img;
|
||||||
|
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
if (message.attachments.length > 0) {
|
if (message.attachments.size > 0) {
|
||||||
img = message.attachments[0].url;
|
img = [...msg.attachments.values()][0].url;
|
||||||
if (gif && (await isGif(img))) {
|
if (gif && (await isGif(img))) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,8 +112,9 @@ const urlRegex = /((https?):\/)?\/?([^:/\s]+)((\/\w+)*\/)([\w\-.]+)/;
|
||||||
async function getImage(msg, str) {
|
async function getImage(msg, str) {
|
||||||
const refMsg = msg.referencedMessage;
|
const refMsg = msg.referencedMessage;
|
||||||
if (refMsg) {
|
if (refMsg) {
|
||||||
if (refMsg.attachments[0] && refMsg.attachments[0].url) {
|
const attachments = [...refMsg.attachments.values()];
|
||||||
return refMsg.attachments[0].url;
|
if (attachments[0]?.url) {
|
||||||
|
return attachments[0].url;
|
||||||
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(refMsg.content)) {
|
} 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];
|
const id = refMsg.content.match(/<a?:[a-zA-Z0-9_]*:([0-9]*)>/)[1];
|
||||||
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
|
return `https://cdn.discordapp.com/emojis/${id}.png?v=1`;
|
||||||
|
@ -134,8 +135,9 @@ async function getImage(msg, str) {
|
||||||
if (img) return img;
|
if (img) return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.attachments[0] && msg.attachments[0].url) {
|
const attachments = [...msg.attachments.values()];
|
||||||
return msg.attachments[0].url;
|
if (attachments[0]?.url) {
|
||||||
|
return attachments[0]?.url;
|
||||||
} else if (urlRegex.test(str)) {
|
} else if (urlRegex.test(str)) {
|
||||||
return str;
|
return str;
|
||||||
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(str)) {
|
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(str)) {
|
||||||
|
|
Loading…
Reference in a new issue