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
8033383b91
commit
9dbaad5e6a
@ -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
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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) {
|
||||
|
@ -44,7 +44,7 @@ export const reqInterval = {
|
||||
}
|
||||
|
||||
/*
|
||||
* MiaoApi私有的面板更新服务
|
||||
* 喵喵Api私有的面板更新服务
|
||||
* 供Yunzai开发者及有投喂的老板们小范围使用
|
||||
* 需要具备Token才会启用~
|
||||
* */
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
}
|
||||
|
38
models/mys-lib/YzMysApi.js
Normal file
38
models/mys-lib/YzMysApi.js
Normal file
@ -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
|
@ -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
|
@ -42,7 +42,7 @@
|
||||
</ul>
|
||||
<div class="data-info">
|
||||
{{if data.dataSource}}
|
||||
<span>数据源:{{ {miao:"MiaoApi",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }}</span>
|
||||
<span>数据源:{{ {miao:"喵喵Api",enka:"Enka.Network",input:"手工录入"}[data.dataSource]||data.dataSource }}</span>
|
||||
{{/if}}
|
||||
{{if data.updateTime}}
|
||||
<span class="time">{{data.updateTime}}</span>
|
||||
|
Loading…
Reference in New Issue
Block a user