mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-10-14 05:39:18 +00:00
fix:修复获取图片错误
This commit is contained in:
parent
1e56fc66ce
commit
d2724e54bf
@ -3,12 +3,13 @@ export default class YunzaiUtils {
|
|||||||
* 获取消息中的图片
|
* 获取消息中的图片
|
||||||
* @param e
|
* @param e
|
||||||
* @param limit 限制
|
* @param limit 限制
|
||||||
* @returns {Promise<*[]>}
|
* @returns {Promise<string[]>}
|
||||||
*/
|
*/
|
||||||
static async getImages(e, limit = 1) {
|
static async getImages(e, limit = 1) {
|
||||||
let imgUrls = [];
|
let imgUrls = [];
|
||||||
const me = `https://q1.qlogo.cn/g?b=qq&s=640&nk=${e.user_id}`;
|
const me = `https://q1.qlogo.cn/g?b=qq&s=640&nk=${e.user_id}`;
|
||||||
//消息中的图片
|
|
||||||
|
// 获取引用消息
|
||||||
if (e.source || e.reply_id) {
|
if (e.source || e.reply_id) {
|
||||||
let reply;
|
let reply;
|
||||||
if (e.getReply) reply = await e.getReply();
|
if (e.getReply) reply = await e.getReply();
|
||||||
@ -17,19 +18,18 @@ export default class YunzaiUtils {
|
|||||||
e.isGroup ? e.source.seq : e.source.time,
|
e.isGroup ? e.source.seq : e.source.time,
|
||||||
1
|
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) {
|
if (!imgUrls.length && e.message) {
|
||||||
imgUrls = e.message.filter((m) => m.type === 'image').map((m) => m.url);
|
imgUrls = e.message.filter((m) => m.type === 'image').map((m) => m.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
//没图时用头像
|
|
||||||
if (!imgUrls.length) imgUrls = [me];
|
if (!imgUrls.length) imgUrls = [me];
|
||||||
imgUrls = imgUrls.slice(0, limit);
|
return imgUrls.slice(0, limit);
|
||||||
return imgUrls;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user