From 9f758044059e4e62bd2830dc18fec48b52e095b9 Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Fri, 25 Nov 2022 02:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=8E=BB=E9=99=A4V2/V3?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=80=BB=E8=BE=91=EF=BC=8C=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E4=BD=BF=E7=94=A8e.runtime=E8=BF=9B=E8=A1=8C=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/character/AvatarWife.js | 2 +- components/Version.js | 5 +- components/common-lib/render.js | 61 +++-------------------- config/system/cfg_system.js | 2 +- index.js | 18 +++++-- models/MysApi.js | 25 +++++----- models/mys-lib/YzMysApi.js | 38 -------------- models/mys-lib/YzMysInfo.js | 66 ------------------------- resources/character/profile-detail.css | 3 ++ resources/character/profile-detail.html | 17 ++++--- resources/character/profile-detail.less | 3 ++ 11 files changed, 54 insertions(+), 186 deletions(-) delete mode 100644 models/mys-lib/YzMysApi.js delete mode 100644 models/mys-lib/YzMysInfo.js diff --git a/apps/character/AvatarWife.js b/apps/character/AvatarWife.js index aa1b344b..0de0d71d 100644 --- a/apps/character/AvatarWife.js +++ b/apps/character/AvatarWife.js @@ -1,7 +1,7 @@ // #老婆 import lodash from 'lodash' import { Common } from '../../components/index.js' -import { Character, MysApi } from '../../models/index.js' +import { Character, MysApi, AvatarList } from '../../models/index.js' import { getAvatarList, renderAvatar } from './AvatarCard.js' const relationMap = { diff --git a/components/Version.js b/components/Version.js index 45cd41b2..dd007203 100644 --- a/components/Version.js +++ b/components/Version.js @@ -26,7 +26,7 @@ try { logs = fs.readFileSync(_logPath, 'utf8') || '' logs = logs.split('\n') - let temp = {}; + let temp = {} let lastLine = {} lodash.forEach(logs, (line) => { if (versionCount <= -1) { @@ -83,6 +83,9 @@ let Version = { }, get changelogs () { return changelogs + }, + runtime () { + console.log(`未能找到e.runtime,请升级至最新版${isV3 ? 'V3' : 'V2'}-Yunzai以使用miao-plugin`) } } diff --git a/components/common-lib/render.js b/components/common-lib/render.js index 207d3821..75ccebc4 100644 --- a/components/common-lib/render.js +++ b/components/common-lib/render.js @@ -1,13 +1,11 @@ -import { Data, Version } from '../index.js' +import { Version } from '../index.js' import Cfg from '../Cfg.js' -import fs from 'fs' -import { puppeteer } from '../../adapter/index.js' -const plugin = 'miao-plugin' -const _path = process.cwd() - -// 尝试性接入,待稳定后替换 -let runtimeRender = async function (e, path, params, cfg) { +export default async function (path, params, cfg) { + let { e } = cfg + if (!e.runtime) { + console.log('未找到e.runtime,请升级至最新版Yunzai') + } return e.runtime.render('miao-plugin', path, params, { retType: cfg.retMsgId ? 'msgId' : 'default', beforeRender ({ data }) { @@ -28,50 +26,3 @@ let runtimeRender = async function (e, path, params, cfg) { } }) } - -export default async function (path, params, cfg) { - let { e } = cfg - if (e.runtime) { - return runtimeRender(e, path, params, cfg) - } - let [app, tpl] = path.split('/') - let layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/' - let resPath = `../../../../../plugins/${plugin}/resources/` - Data.createDir(`data/html/${plugin}/${app}/${tpl}`, 'root') - let data = { - ...params, - _plugin: plugin, - saveId: params.saveId || params.save_id || tpl, - tplFile: `./plugins/${plugin}/resources/${app}/${tpl}.html`, - pluResPath: resPath, - _res_path: resPath, - _layout_path: layoutPath, - _tpl_path: process.cwd() + '/plugins/miao-plugin/resources/common/tpl/', - defaultLayout: layoutPath + 'default.html', - elemLayout: layoutPath + 'elem.html', - pageGotoParams: { - waitUntil: 'networkidle0' - }, - sys: { - scale: Cfg.scale(cfg.scale || 1), - copyright: `Created By Yunzai-Bot${Version.yunzai} & Miao-Plugin${Version.version}` - } - } - if (process.argv.includes('web-debug')) { - // debug下保存当前页面的渲染数据,方便模板编写与调试 - // 由于只用于调试,开发者只关注自己当时开发的文件即可,暂不考虑app及plugin的命名冲突 - let saveDir = _path + '/data/ViewData/' - if (!fs.existsSync(saveDir)) { - fs.mkdirSync(saveDir) - } - let file = saveDir + tpl + '.json' - data._app = app - fs.writeFileSync(file, JSON.stringify(data)) - } - let base64 = await puppeteer.screenshot(`miao-plugin/${app}/${tpl}`, data) - let ret = true - if (base64) { - ret = await e.reply(base64) - } - return cfg.retMsgId ? ret : true -} diff --git a/config/system/cfg_system.js b/config/system/cfg_system.js index c284c3ef..9efaa78a 100644 --- a/config/system/cfg_system.js +++ b/config/system/cfg_system.js @@ -113,7 +113,7 @@ export const cfgSchema = { title: '面板计算属性', key: '计算', def: false, - desc: '实验特性:#雷神面板 使用面板计算属性取代展柜属性' + desc: '#雷神面板 使用面板计算属性取代展柜属性。功能实验中,开启后可能会有角色面板数据错误,请慎重开启' } } } diff --git a/index.js b/index.js index f7a4f638..94e24c91 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ import { Data, Version } from './components/index.js' +import fs from 'fs' export * from './apps/index.js' @@ -13,11 +14,9 @@ setTimeout(async function () { let msgStr = await redis.get('miao:restart-msg') let relpyPrivate = async function () { } - if (!Version.isV3) { - let common = await Data.importModule('lib/common.js') - if (common && common.default && common.default.relpyPrivate) { - relpyPrivate = common.default.relpyPrivate - } + let common = await Data.importModule(Version.isV3 ? 'lib/common/common.js' : 'lib/common.js', 'root') + if (common && common.default && common.default.relpyPrivate) { + relpyPrivate = common.default.relpyPrivate } if (msgStr) { let msg = JSON.parse(msgStr) @@ -26,4 +25,13 @@ setTimeout(async function () { let msgs = [`当前喵喵版本: ${Version.version}`, '您可使用 #喵喵版本 命令查看更新信息'] await relpyPrivate(msg.qq, msgs.join('\n')) } + if (!fs.existsSync(process.cwd() + (Version.isV3 ? '/lib/plugins/runtime.js' : '/lib/adapter/runtime.js'))) { + let msg = '警告:未检测到runtime,miao-plugin可能无法正常工作。请升级至最新版Yunzai以使用miao-plugin' + if (!await redis.get('miao:runtime-warning')) { + await relpyPrivate(msg.qq, msg) + await redis.set('miao:runtime-warning', 'true', { EX: 3600 * 24 }) + } else { + console.log(msg) + } + } }, 1000) diff --git a/models/MysApi.js b/models/MysApi.js index cd408771..2856b5ab 100644 --- a/models/MysApi.js +++ b/models/MysApi.js @@ -1,6 +1,5 @@ import { User } from './index.js' -import YzMysInfo from './mys-lib/YzMysInfo.js' -import YzMysApi from './mys-lib/YzMysApi.js' +import { Version } from '../components/index.js' export default class MysApi { constructor (e, uid, mysInfo) { @@ -14,16 +13,16 @@ export default class MysApi { } static async init (e, cfg = 'all') { + if (!e.runtime) { + Version.runtime() + return false + } if (typeof (cfg) === 'string') { cfg = { auth: cfg } } let { auth = 'all' } = cfg let mys = false - if (e.runtime) { - mys = await e.runtime.getMysInfo(auth) - } else { - mys = await YzMysInfo.init(e, auth === 'cookie' ? 'detail' : 'roleIndex') - } + mys = await e.runtime.getMysInfo(auth) if (!mys) { return false } @@ -33,10 +32,14 @@ export default class MysApi { } static async initUser (e, cfg = 'all') { + if (!e.runtime) { + Version.runtime() + return false + } if (typeof (cfg) === 'string') { cfg = { auth: cfg } } - let uid = await YzMysInfo.getUid(e) + let uid = e.runtime?.uid if (uid) { return new User({ id: e.user_id, uid: uid }) } @@ -63,11 +66,11 @@ export default class MysApi { return new User({ id: this.e.user_id, uid: this.uid }) } - getMysApi (e) { + async getMysApi (e, targetType = 'all', option = {}) { if (this.mys) { return this.mys } - this.mys = new YzMysApi(this.uid, this.ck, { log: false, e }) + this.mys = await e.runtime.getMysApi(targetType, option) return this.mys } @@ -76,7 +79,7 @@ export default class MysApi { return false } let e = this.e - let mys = this.getMysApi(e) + let mys = await this.getMysApi(e, api, { log: false }) // 暂时先在plugin侧阻止错误,防止刷屏 e._original_reply = e._original_reply || e.reply e._reqCount = e._reqCount || 0 diff --git a/models/mys-lib/YzMysApi.js b/models/mys-lib/YzMysApi.js deleted file mode 100644 index c3f43043..00000000 --- a/models/mys-lib/YzMysApi.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Data } from '../../components/index.js' - -let YzMysApi = false - -async function init () { - let mys = await Data.importModule('plugins/genshin/model/mys/mysApi.js', 'root') - if (mys && mys.default) { - YzMysApi = mys.default - return - } -} - -await init() -if (!YzMysApi) { - // v2兼容处理 - YzMysApi = class { - constructor (uid, ck, { e }) { - this.e = e - } - - async getData (api, data) { - this.mysApi = this.mysApi || await this.e.getMysApi({ - auth: 'all', - targetType: 'all', - cookieType: 'all' - }) - if (!this.mysApi) { - return false - } - let ret = await this.mysApi.getData(api, data) - if (ret) { - return { data: ret } - } - return false - } - } -} -export default YzMysApi diff --git a/models/mys-lib/YzMysInfo.js b/models/mys-lib/YzMysInfo.js deleted file mode 100644 index 67639496..00000000 --- a/models/mys-lib/YzMysInfo.js +++ /dev/null @@ -1,66 +0,0 @@ -import { Data } from '../../components/index.js' - -let YzMysInfo = false -let MysUser = false - -async function init () { - let mys = await Data.importModule('plugins/genshin/model/mys/mysInfo.js', 'root') - if (mys && mys.default) { - YzMysInfo = mys.default - } else { - let module = await Data.importModule('lib/components/models/MysUser.js', 'root') - if (module && module.default) { - MysUser = module.default - } - } -} - -await init() - -if (!YzMysInfo) { - // v2 MysInfo - YzMysInfo = class { - constructor (e, uid, cookieUser) { - if (e) { - this.e = e - this.userId = String(e.user_id) - } - this.uid = uid - this.ckInfo = { - ck: cookieUser.cookie, - uid: cookieUser.uid - } - } - - static async init (e, api) { - let MysApi = await e.getMysApi({ - auth: 'all', - targetType: 'all', - cookieType: api === 'detail' ? 'self:' : 'all' - }) // V2兼容 - let { selfUser, targetUser, cookieUser } = MysApi - let mys = new YzMysInfo(e, targetUser.uid || selfUser.uid, cookieUser) - mys._MysApi = MysApi - return mys - } - - // 检查当前UID是否有CK绑定 - static async checkUidBing (uid) { - let user = await MysUser.get(uid) - return user.cookie - } - - static async getUid (e) { - let user = await e.checkAuth({ - auth: 'all' - }) - if (!user || !user.getMysUser) { - return false - } - let mysUser = await user.getMysUser() - return mysUser ? mysUser.uid : false - } - } -} - -export default YzMysInfo diff --git a/resources/character/profile-detail.css b/resources/character/profile-detail.css index 20df6269..3312381d 100644 --- a/resources/character/profile-detail.css +++ b/resources/character/profile-detail.css @@ -256,6 +256,9 @@ body { background-image: url(../common/bg/bg-pyro.jpg); } .data-info { + position: absolute; + bottom: -10px; + right: 15px; font-size: 12px; color: rgba(255, 255, 255, 0.85); text-align: right; diff --git a/resources/character/profile-detail.html b/resources/character/profile-detail.html index 437736f1..4baf64a2 100644 --- a/resources/character/profile-detail.html +++ b/resources/character/profile-detail.html @@ -40,14 +40,6 @@
  • 元素充能{{attr.recharge}}
  • 伤害加成{{attr.dmg}}
  • -
    - {{if data.dataSource}} - {{if data._attrCalc}}[ 面板属性计算:开启 ] ·{{/if}} 数据源:{{ {miao:"喵喵Api",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }} - {{/if}} - {{if data.updateTime}} - {{data.updateTime}} - {{/if}} -
    @@ -61,6 +53,15 @@
    {{/each}} + +
    + {{if data.dataSource}} + {{if data._attrCalc}}[面板计算:开启] ·{{/if}} 数据源:{{ {miao:"喵喵Api",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }} + {{/if}} + {{if data.updateTime}} + {{data.updateTime}} + {{/if}} +
    {{if mode === "profile" && dataSource !== "input2"}} diff --git a/resources/character/profile-detail.less b/resources/character/profile-detail.less index b85b5041..50cbf4a5 100644 --- a/resources/character/profile-detail.less +++ b/resources/character/profile-detail.less @@ -310,6 +310,9 @@ body { } .data-info { + position: absolute; + bottom: -10px; + right: 15px; font-size: 12px; color: rgba(255, 255, 255, .85); text-align: right;