From d2724e54bf7f3604deb3afc89faf91d2a38a0ecf Mon Sep 17 00:00:00 2001 From: Jerryplusy Date: Sat, 4 Oct 2025 23:44:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/yunzai/utils.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/yunzai/utils.js b/lib/yunzai/utils.js index 9f9e850..04b6e37 100644 --- a/lib/yunzai/utils.js +++ b/lib/yunzai/utils.js @@ -3,12 +3,13 @@ export default class YunzaiUtils { * 获取消息中的图片 * @param e * @param limit 限制 - * @returns {Promise<*[]>} + * @returns {Promise} */ static async getImages(e, limit = 1) { let imgUrls = []; const me = `https://q1.qlogo.cn/g?b=qq&s=640&nk=${e.user_id}`; - //消息中的图片 + + // 获取引用消息 if (e.source || e.reply_id) { let reply; if (e.getReply) reply = await e.getReply(); @@ -17,19 +18,18 @@ export default class YunzaiUtils { e.isGroup ? e.source.seq : e.source.time, 1 ); - reply = history?.pop()?.message; + reply = history?.pop(); } - if (reply) imgUrls = reply.filter((m) => m.type === 'image').map((m) => m.url); - } - //当前消息中的图片 + if (reply) { + const msgArr = Array.isArray(reply) ? reply : reply.message || []; + imgUrls = msgArr.filter((m) => m.type === 'image').map((m) => m.url); + } + } if (!imgUrls.length && e.message) { imgUrls = e.message.filter((m) => m.type === 'image').map((m) => m.url); } - - //没图时用头像 if (!imgUrls.length) imgUrls = [me]; - imgUrls = imgUrls.slice(0, limit); - return imgUrls; + return imgUrls.slice(0, limit); } }