feat: 获取原图

This commit is contained in:
bietiaop 2024-08-01 20:30:21 +08:00
parent 67c0bf7a0b
commit 6ba33447c0
2 changed files with 46 additions and 2 deletions

View file

@ -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;
}
}

View file

@ -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');
}
// 获取渲染精度配置