mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-21 22:48:13 +00:00
支持直接查看角色照片
This commit is contained in:
parent
b6babcf15b
commit
7f2b058951
19
apps/wiki.js
19
apps/wiki.js
@ -7,7 +7,7 @@ import lodash from "lodash";
|
||||
|
||||
let action = {
|
||||
wiki: {
|
||||
keyword: "命座|天赋|技能|资料"
|
||||
keyword: "命座|天赋|技能|资料|照片|写真|图片|插画"
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,20 +18,33 @@ export async function wiki(e, { render }) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let reg = /#?(.+)(命座|命之座|天赋|技能|资料)$/, msg = e.msg;
|
||||
let reg = /#?(.+)(命座|命之座|天赋|技能|资料|照片|写真|图片|插画)$/, msg = e.msg;
|
||||
let ret = reg.exec(msg);
|
||||
|
||||
if (!ret && !ret[1] && !ret[2]) {
|
||||
if (!ret || !ret[1] || !ret[2]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mode = "talent";
|
||||
if (/命/.test(ret[2])) {
|
||||
mode = "cons";
|
||||
} else if (/图|画|写真|照片/.test(ret[2])) {
|
||||
mode = "pic";
|
||||
}
|
||||
|
||||
|
||||
let char = Character.get(ret[1]);
|
||||
|
||||
if (mode === "pic") {
|
||||
let img = char.getCardImg(false);
|
||||
if (img && img.img) {
|
||||
e.reply(segment.image(process.cwd() + "/plugins/miao-plugin/resources/" + img.img));
|
||||
} else {
|
||||
e.reply("暂无图片");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let base64 = await render("wiki", "character", {
|
||||
save_id: "天赋" + char.name,
|
||||
...char,
|
||||
|
@ -4,6 +4,7 @@ import fs from "fs";
|
||||
import Data from "../Data.js";
|
||||
import request from "request";
|
||||
import path from "path";
|
||||
import sizeOf from "image-size";
|
||||
|
||||
let characterMap = {};
|
||||
const _path = process.cwd();
|
||||
@ -18,21 +19,52 @@ class Character extends Base {
|
||||
let data = Data.readJSON(`${_path}/plugins/miao-plugin/resources/meta/character/${this.name}/`, "data.json");
|
||||
lodash.extend(this, data);
|
||||
}
|
||||
/*
|
||||
get name() {
|
||||
if (this.roleId) {
|
||||
if (this.roleId * 1 === 10000005) {
|
||||
this.name = "空";
|
||||
} else if (this.roleId * 1 === 10000007) {
|
||||
this.name = "荧";
|
||||
|
||||
getCardImg(def = true) {
|
||||
let name = this.name;
|
||||
|
||||
if (!fs.existsSync(`./plugins/miao-plugin/resources/character-img/${name}/`)) {
|
||||
fs.mkdirSync(`./plugins/miao-plugin/resources/character-img/${name}/`);
|
||||
}
|
||||
|
||||
let list = {};
|
||||
let imgs = fs.readdirSync(`./plugins/miao-plugin/resources/character-img/${name}/`);
|
||||
imgs = imgs.filter((img) => /\.(png|jpg|webp)/.test(img));
|
||||
|
||||
lodash.forEach(imgs, (img) => {
|
||||
list[img] = `character-img/${name}/${img}`
|
||||
});
|
||||
|
||||
const plusPath = `./plugins/miao-plugin/resources/miao-res-plus/`;
|
||||
if (fs.existsSync(plusPath)) {
|
||||
if (!fs.existsSync(`${plusPath}/character-img/${name}/`)) {
|
||||
fs.mkdirSync(`${plusPath}/character-img/${name}/`);
|
||||
}
|
||||
|
||||
let imgs = fs.readdirSync(`${plusPath}/character-img/${name}/`);
|
||||
imgs = imgs.filter((img) => /\.(png|jpg|webp)/.test(img));
|
||||
lodash.forEach(imgs, (img) => {
|
||||
list[img] = `miao-res-plus/character-img/${name}/${img}`
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let img = lodash.sample(lodash.values(list));
|
||||
|
||||
|
||||
if (!img) {
|
||||
if (def) {
|
||||
img = "/character-img/default/01.jpg";
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return this._name;
|
||||
}
|
||||
|
||||
set name(name) {
|
||||
this._name = name;
|
||||
}*/
|
||||
let ret = sizeOf(`./plugins/miao-plugin/resources/${img}`);
|
||||
ret.img = img;
|
||||
ret.mode = ret.width > ret.height ? "left" : "bottom";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user