mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-21 22:48:13 +00:00
初步去除V2/V3兼容逻辑,开始使用e.runtime进行适配
This commit is contained in:
parent
75e63b0894
commit
9f75804405
@ -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 = {
|
||||
|
@ -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`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<span class="version">${Version.yunzai}</span> & Miao-Plugin<span class="version">${Version.version}</span>`
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ export const cfgSchema = {
|
||||
title: '面板计算属性',
|
||||
key: '计算',
|
||||
def: false,
|
||||
desc: '实验特性:#雷神面板 使用面板计算属性取代展柜属性'
|
||||
desc: '#雷神面板 使用面板计算属性取代展柜属性。功能实验中,开启后可能会有角色面板数据错误,请慎重开启'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
index.js
18
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)
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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;
|
||||
|
@ -40,14 +40,6 @@
|
||||
<li><i class="i-re"></i>元素充能<strong>{{attr.recharge}}</strong></li>
|
||||
<li><i class="i-dmg"></i>伤害加成<strong>{{attr.dmg}}</strong></li>
|
||||
</ul>
|
||||
<div class="data-info">
|
||||
{{if data.dataSource}}
|
||||
<span>{{if data._attrCalc}}[ 面板属性计算:开启 ] ·{{/if}} 数据源:{{ {miao:"喵喵Api",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }}</span>
|
||||
{{/if}}
|
||||
{{if data.updateTime}}
|
||||
<span class="time">{{data.updateTime}}</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="char-cons">
|
||||
@ -61,6 +53,15 @@
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div class="data-info">
|
||||
{{if data.dataSource}}
|
||||
<span>{{if data._attrCalc}}[面板计算:开启] ·{{/if}} 数据源:{{ {miao:"喵喵Api",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }}</span>
|
||||
{{/if}}
|
||||
{{if data.updateTime}}
|
||||
<span class="time">{{data.updateTime}}</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if mode === "profile" && dataSource !== "input2"}}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user