From 9dbaad5e6ac552e2b2c2cf18dfdccef38b999a77 Mon Sep 17 00:00:00 2001 From: yoimiya-kokomi <592981798@qq.com> Date: Fri, 21 Oct 2022 22:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=A9=E8=B5=8B=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84=E9=80=BB=E8=BE=91=E5=8F=8A=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wiki.js | 8 ----- components/profile-data/miao-data.js | 2 +- components/profile-data/miao.js | 2 +- config/profile_default.js | 2 +- models/MysApi.js | 28 ++++++++++----- models/ProfileData.js | 2 +- models/mys-lib/YzMysApi.js | 38 +++++++++++++++++++++ models/mys-lib/{MysInfo.js => YzMysInfo.js} | 25 +++++--------- resources/character/profile-detail.html | 2 +- 9 files changed, 70 insertions(+), 39 deletions(-) create mode 100644 models/mys-lib/YzMysApi.js rename models/mys-lib/{MysInfo.js => YzMysInfo.js} (72%) diff --git a/apps/wiki.js b/apps/wiki.js index d61f763d..5c0faf95 100644 --- a/apps/wiki.js +++ b/apps/wiki.js @@ -5,12 +5,6 @@ import { Format, Cfg, Common, App } from '../components/index.js' import { Character } from '../models/index.js' import CharWiki from './wiki/CharWiki.js' -// eslint-disable-next-line no-unused-vars -let action = { - wiki: { - keyword: '命座|天赋|技能|资料|照片|写真|图片|插画' - } -} let wikiReg = /^(?:#|喵喵)?(.*)(天赋|技能|命座|命之座|资料|图鉴|照片|写真|图片|图像)$/ let app = App.init({ @@ -35,7 +29,6 @@ function checkCharacter (e) { return false } let ret = wikiReg.exec(msg) - console.log(msg, ret) if (!ret || !ret[1] || !ret[2]) { return false } @@ -66,7 +59,6 @@ function checkCharacter (e) { } async function wiki (e) { - let mode = e.wikiMode let char = e.char diff --git a/components/profile-data/miao-data.js b/components/profile-data/miao-data.js index 7463e55c..4a1deea5 100644 --- a/components/profile-data/miao-data.js +++ b/components/profile-data/miao-data.js @@ -4,7 +4,7 @@ import { artiIdx, artiSetMap, attrMap } from './miao-meta.js' let MiaoData = { key: 'miao', - name: 'MiaoApi', + name: '喵喵Api', getData (uid, data) { let ret = { diff --git a/components/profile-data/miao.js b/components/profile-data/miao.js index a866b4c2..1160a74b 100644 --- a/components/profile-data/miao.js +++ b/components/profile-data/miao.js @@ -5,7 +5,7 @@ import MiaoData from './miao-data.js' export default new ProfileServ({ key: 'miao', - name: 'MiaoApi', + name: '喵喵Api', cfgKey: 'miaoApi', async response (data, req) { if (data.status !== 0) { diff --git a/config/profile_default.js b/config/profile_default.js index 1a9763e8..ba9b1dcf 100644 --- a/config/profile_default.js +++ b/config/profile_default.js @@ -44,7 +44,7 @@ export const reqInterval = { } /* -* MiaoApi私有的面板更新服务 +* 喵喵Api私有的面板更新服务 * 供Yunzai开发者及有投喂的老板们小范围使用 * 需要具备Token才会启用~ * */ diff --git a/models/MysApi.js b/models/MysApi.js index c5a6e831..a77a0504 100644 --- a/models/MysApi.js +++ b/models/MysApi.js @@ -1,11 +1,12 @@ import { User } from './index.js' -import MysInfo from './mys-lib/MysInfo.js' +import YzMysInfo from './mys-lib/YzMysInfo.js' +import YzMysApi from './mys-lib/YzMysApi.js' export default class MysApi { - constructor (e, uid, MysApi) { + constructor (e, uid, mysInfo) { this.e = e - this.MysApi = MysApi - this.ckInfo = MysApi.ckInfo + this.mysInfo = mysInfo + this.ckInfo = mysInfo.ckInfo this.uid = uid e.targetUser = this.targetUser e.selfUser = this.selfUser @@ -17,7 +18,7 @@ export default class MysApi { cfg = { auth: cfg } } let { auth = 'all' } = cfg - let mys = await MysInfo.init(e, 'roleIndex') + let mys = await YzMysInfo.init(e, 'roleIndex') if (!mys) { return false } @@ -37,7 +38,7 @@ export default class MysApi { if (typeof (cfg) === 'string') { cfg = { auth: cfg } } - let uid = await MysInfo.getUid(e) + let uid = await YzMysInfo.getUid(e) if (uid) { return new User({ id: e.user_id, uid: uid }) } @@ -45,7 +46,7 @@ export default class MysApi { } get isSelfCookie () { - return this.uid * 1 === this.ckUid * 1 || this?.MysApi?.isSelf + return this.uid * 1 === this.ckUid * 1 || this?.mysInfo?.isSelf } get ckUid () { @@ -64,11 +65,20 @@ export default class MysApi { return new User({ id: this.e.user_id, uid: this.uid }) } + getMysApi (e) { + if (this.mys) { + return this.mys + } + this.mys = new YzMysApi(this.uid, this.ck, { log: false, e }) + return this.mys + } + async getData (api, data) { - if (!this.MysApi) { + if (!this.mysInfo) { return false } let e = this.e + let mys = this.getMysApi(e) // 暂时先在plugin侧阻止错误,防止刷屏 e._original_reply = e._original_reply || e.reply e._reqCount = e._reqCount || 0 @@ -81,7 +91,7 @@ export default class MysApi { } } e._reqCount++ - let ret = await MysInfo.get(this.e, api, data) + let ret = await mys.getData(api, data) e._reqCount-- if (e._reqCount === 0) { e.reply = e._original_reply diff --git a/models/ProfileData.js b/models/ProfileData.js index aecf171c..98b9d391 100644 --- a/models/ProfileData.js +++ b/models/ProfileData.js @@ -129,7 +129,7 @@ export default class ProfileData extends Base { get dataSourceName () { return { enka: 'Enka.Network', - miao: 'MiaoApi', + miao: '喵喵Api', input: 'Input' }[this.dataSource] || 'Enka.NetWork' } diff --git a/models/mys-lib/YzMysApi.js b/models/mys-lib/YzMysApi.js new file mode 100644 index 00000000..c3f43043 --- /dev/null +++ b/models/mys-lib/YzMysApi.js @@ -0,0 +1,38 @@ +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/MysInfo.js b/models/mys-lib/YzMysInfo.js similarity index 72% rename from models/mys-lib/MysInfo.js rename to models/mys-lib/YzMysInfo.js index 4fcf5a01..b0602c9d 100644 --- a/models/mys-lib/MysInfo.js +++ b/models/mys-lib/YzMysInfo.js @@ -1,12 +1,12 @@ -import { Data, Version } from '../../components/index.js' +import { Data } from '../../components/index.js' -let MysInfo = false +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) { - MysInfo = mys.default + YzMysInfo = mys.default } else { let module = await Data.importModule('lib/components/models/MysUser.js', 'root') if (module && module.default) { @@ -17,14 +17,14 @@ async function init () { await init() -if (!MysInfo) { +if (!YzMysInfo) { // v2 MysInfo const apiCfg = { auth: 'all', targetType: 'all', - cookieType: 'all', + cookieType: 'all' } - MysInfo = class { + YzMysInfo = class { constructor (e, uid, cookieUser) { if (e) { this.e = e @@ -40,7 +40,7 @@ if (!MysInfo) { static async init (e) { let MysApi = await e.getMysApi(apiCfg) // V2兼容 let { selfUser, targetUser, cookieUser } = MysApi - let mys = new MysInfo(e, targetUser.uid || selfUser.uid, cookieUser) + let mys = new YzMysInfo(e, targetUser.uid || selfUser.uid, cookieUser) mys._MysApi = MysApi return mys } @@ -61,16 +61,7 @@ if (!MysInfo) { let mysUser = await user.getMysUser() return mysUser ? mysUser.uid : false } - - static async get (e, api, data) { - let MysApi = await e.getMysApi(apiCfg) // V2兼容 - let ret = await MysApi.getData(api, data) - if (ret) { - return { data: ret } - } - return false - } } } -export default MysInfo +export default YzMysInfo diff --git a/resources/character/profile-detail.html b/resources/character/profile-detail.html index 5f88a862..c946fc6e 100644 --- a/resources/character/profile-detail.html +++ b/resources/character/profile-detail.html @@ -42,7 +42,7 @@