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;
|
||||
|
||||
for (const message of messages) {
|
||||
if (message.attachments.length > 0) {
|
||||
img = message.attachments[0].url;
|
||||
if (message.attachments.size > 0) {
|
||||
img = [...msg.attachments.values()][0].url;
|
||||
if (gif && (await isGif(img))) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -112,8 +112,9 @@ 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;
|
||||
const attachments = [...refMsg.attachments.values()];
|
||||
if (attachments[0]?.url) {
|
||||
return 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`;
|
||||
|
@ -134,8 +135,9 @@ async function getImage(msg, str) {
|
|||
if (img) return img;
|
||||
}
|
||||
|
||||
if (msg.attachments[0] && msg.attachments[0].url) {
|
||||
return msg.attachments[0].url;
|
||||
const attachments = [...msg.attachments.values()];
|
||||
if (attachments[0]?.url) {
|
||||
return attachments[0]?.url;
|
||||
} else if (urlRegex.test(str)) {
|
||||
return str;
|
||||
} else if (/<a?:[a-zA-Z0-9_]*:([0-9]*)>/.test(str)) {
|
||||
|
|
Loading…
Reference in a new issue