From 7f2b058951c5c9c5877ead60dca3e98921b9806f Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Sat, 9 Apr 2022 05:52:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E8=A7=92=E8=89=B2=E7=85=A7=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wiki.js | 19 ++++++++++-- components/models/Character.js | 56 ++++++++++++++++++++++++++-------- index.js | 2 +- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/apps/wiki.js b/apps/wiki.js index 89c6960f..89f49005 100644 --- a/apps/wiki.js +++ b/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, diff --git a/components/models/Character.js b/components/models/Character.js index fa3b8a87..10c64416 100644 --- a/components/models/Character.js +++ b/components/models/Character.js @@ -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; + } } diff --git a/index.js b/index.js index 0378caa3..2ddbe489 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ let rule = { reg: "^#深渊(第?.{1,2}层)?(角色)?出场(率|统计)*$", }, wiki: { - reg: "^#.*(天赋|技能|命座|命之座|资料)$", + reg: "^#.*(天赋|技能|命座|命之座|资料|照片|写真|图片|插画)$", }, ...adminRule };