From 6ba33447c0a36487e95f155d8762652300437229 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Thu, 1 Aug 2024 20:30:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E5=8E=9F=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/panel.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- lib/render.js | 2 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/apps/panel.js b/apps/panel.js index 1727f0b..39fcf90 100644 --- a/apps/panel.js +++ b/apps/panel.js @@ -21,6 +21,10 @@ export class Panel extends ZZZPlugin { reg: `${rulePrefix}练度(统计)?$`, fnc: 'proficiency', }, + { + reg: `${rulePrefix}原图$`, + fnc: 'getCharOriImage', + }, ], }); } @@ -111,7 +115,18 @@ export class Panel extends ZZZPlugin { uid: uid, charData: data, }; - await render(this.e, 'panel/card.html', finalData); + + const res = await this.reply( + render(this.e, 'panel/card.html', finalData, { + retType: 'base64', + }) + ); + if (res?.message_id) + await redis.set(`ZZZ:PANEL:IMAGE:${res.message_id}`, data.role_icon, { + EX: 3600 * 3, + }); + + return false; } async proficiency() { const uid = await this.getUID(); @@ -158,4 +173,33 @@ export class Panel extends ZZZPlugin { }; await render(this.e, 'proficiency/index.html', finalData); } + async getCharOriImage() { + let source; + if (this.e.getReply) { + source = await this.e.getReply(); + } else if (this.e.source) { + if (this.e.group?.getChatHistory) { + // 支持at图片添加,以及支持后发送 + source = ( + await this.e.group.getChatHistory(this.e.source?.seq, 1) + ).pop(); + } else if (this.e.friend?.getChatHistory) { + source = ( + await this.e.friend.getChatHistory(this.e.source?.time + 1, 1) + ).pop(); + } + } + const id = source?.message_id; + if (!id) { + await this.reply('未找到消息源,请引用要查看的图片'); + return false; + } + const image = await redis.get(`ZZZ:PANEL:IMAGE:${id}`); + if (!image) { + await this.reply('未找到原图'); + return false; + } + await this.reply(segment.image(image)); + return false; + } } diff --git a/lib/render.js b/lib/render.js index cc39ddf..c1d5bc4 100644 --- a/lib/render.js +++ b/lib/render.js @@ -14,7 +14,7 @@ import version from './version.js'; const render = (e, renderPath, renderData = {}, cfg = {}) => { // 判断是否存在e.runtime if (!e.runtime) { - console.log('未找到e.runtime,请升级至最新版Yunzai'); + logger.error('未找到e.runtime,请升级至最新版Yunzai'); } // 获取渲染精度配置