Merge pull request #31 from zolay-poi/master

新增`#获取原图`指令,用于获取角色卡片的原图
This commit is contained in:
Kokomi 2022-06-11 21:55:55 +08:00 committed by GitHub
commit d14999dcb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 5 deletions

View File

@ -390,7 +390,7 @@ async function renderCard(e, avatar, render, renderType = "card") {
e.reply(segment.image(process.cwd() + "/plugins/miao-plugin/resources/" + bg.img));
} else {
//渲染图像
return await Common.render("character/card", {
let msgRes = await Common.render("character/card", {
save_id: uid,
uid,
talent,
@ -400,6 +400,11 @@ async function renderCard(e, avatar, render, renderType = "card") {
...getCharacterData(avatar),
ds: char.getData("name,id,title,desc"),
}, { e, render, scale: 1.6 });
if (msgRes && msgRes.message_id) {
// 如果消息发送成功就将message_id和图片路径存起来1小时过期
await redis.set(`miao:original-picture:${msgRes.message_id}`, bg.img, {EX: 3600});
}
return msgRes;
}
@ -965,3 +970,34 @@ export async function profileHelp(e) {
e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/character/imgs/help.jpg`))
return true;
}
/** 获取角色卡片的原图 */
export async function getOriginalPicture(e) {
if (!e.hasReply) {
return;
}
// 引用的消息不是自己的消息
if (e.source.user_id !== e.self_id) {
return;
}
// 引用的消息不是纯图片
if (!/^\[图片]$/.test(e.source.message)) {
return;
}
// 获取原消息
let source;
if (e.isGroup) {
source = (await e.group.getChatHistory(e.source.seq, 1)).pop();
} else {
source = (await e.friend.getChatHistory(e.source.time, 1)).pop();
}
if (source) {
let imgPath = await redis.get(`miao:original-picture:${source.message_id}`);
if (imgPath) {
e.reply([segment.image(process.cwd() + "/plugins/miao-plugin/resources/" + imgPath)]);
return true;
}
}
e.reply("消息太过久远了,俺也忘了原图是啥了,下次早点来吧~");
return true;
}

View File

@ -18,7 +18,7 @@ export const render = async function (path, params, cfg) {
});
if (base64) {
e.reply(segment.image(`base64://${base64}`));
return await e.reply(segment.image(`base64://${base64}`));
}
return true;

View File

@ -6,7 +6,8 @@ import {
enemyLv,
getArtis,
getProfileAll,
profileHelp
profileHelp,
getOriginalPicture
} from "./apps/character.js";
import { consStat, abyssPct, abyssTeam } from "./apps/stat.js";
import { wiki, calendar } from "./apps/wiki.js";
@ -34,7 +35,8 @@ export {
getProfileAll,
profileHelp,
calendar,
profileCfg
profileCfg,
getOriginalPicture
};
@ -60,6 +62,10 @@ let rule = {
reg: wifeReg,
describe: "【#角色】#老公 #老婆 查询",
},
getOriginalPicture: {
reg: "^#(获取|给我|我要|求|发|发下|发个|发一下)?原图(吧|呗)?$",
describe: "【#原图】 回复角色卡片,可获取原图",
},
consStat: {
reg: "^#(喵喵)?角色(持有|持有率|命座|命之座|.命)(分布|统计|持有|持有率)?$",
describe: "【#统计】 #角色持有率 #角色5命统计",