2022-09-20 11:50:27 +00:00
|
|
|
|
import { User } from './index.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
import { Version } from '#miao'
|
2024-02-04 01:55:48 +00:00
|
|
|
|
import { Button } from '#miao.models'
|
2022-09-20 11:50:27 +00:00
|
|
|
|
|
|
|
|
|
export default class MysApi {
|
2024-04-05 03:28:51 +00:00
|
|
|
|
constructor(e, uid, mysInfo) {
|
2022-09-20 11:50:27 +00:00
|
|
|
|
this.e = e
|
2022-10-21 14:48:19 +00:00
|
|
|
|
this.mysInfo = mysInfo
|
|
|
|
|
this.ckInfo = mysInfo.ckInfo
|
2023-05-09 03:00:37 +00:00
|
|
|
|
this.ckUser = mysInfo.ckUser
|
2022-09-20 11:50:27 +00:00
|
|
|
|
this.uid = uid
|
|
|
|
|
e.targetUser = this.targetUser
|
|
|
|
|
e.selfUser = this.selfUser
|
|
|
|
|
e.isSelfCookie = this.isSelfCookie
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
get isSelfCookie () {
|
|
|
|
|
return this.uid * 1 === this.ckUid * 1 || this?.mysInfo?.isSelf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get ckUid () {
|
|
|
|
|
return this.ckInfo.uid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get ck () {
|
|
|
|
|
return this.ckInfo.ck
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get selfUser () {
|
|
|
|
|
return new User({ id: this.e.user_id, uid: this.uid })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get targetUser () {
|
|
|
|
|
return new User({ id: this.e.user_id, uid: this.uid })
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 08:14:25 +00:00
|
|
|
|
static async init (e, auth = 'all') {
|
2022-11-24 18:17:31 +00:00
|
|
|
|
if (!e.runtime) {
|
|
|
|
|
Version.runtime()
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-11-25 08:14:25 +00:00
|
|
|
|
let mys = await e.runtime.getMysInfo(auth)
|
2022-09-20 11:50:27 +00:00
|
|
|
|
if (!mys) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let uid = mys.uid
|
2022-09-20 19:15:22 +00:00
|
|
|
|
e._mys = new MysApi(e, uid, mys)
|
|
|
|
|
return e._mys
|
2022-09-20 11:50:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 08:14:25 +00:00
|
|
|
|
static async initUser (e, auth = 'all') {
|
2022-12-03 21:17:07 +00:00
|
|
|
|
let { runtime } = e
|
|
|
|
|
if (!runtime) {
|
2022-11-24 18:17:31 +00:00
|
|
|
|
Version.runtime()
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-12-03 21:17:07 +00:00
|
|
|
|
let uid
|
|
|
|
|
if (runtime.getUid) {
|
|
|
|
|
uid = await runtime.getUid()
|
|
|
|
|
} else {
|
|
|
|
|
// 兼容处理老版本Yunzai
|
|
|
|
|
uid = runtime.uid || e.uid
|
|
|
|
|
if (e.at) {
|
|
|
|
|
// 暂时使用MysApi.init替代
|
|
|
|
|
let mys = await MysApi.init(e, auth)
|
|
|
|
|
if (!mys) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
uid = mys.uid || uid
|
2022-11-25 08:14:25 +00:00
|
|
|
|
}
|
2022-09-20 11:50:27 +00:00
|
|
|
|
}
|
|
|
|
|
if (uid) {
|
2022-11-25 08:14:25 +00:00
|
|
|
|
return new User({ id: e.user_id, uid })
|
2022-12-03 21:17:07 +00:00
|
|
|
|
} else {
|
2024-02-04 01:55:48 +00:00
|
|
|
|
e.reply(['请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】', new Button(e).bindUid()])
|
2023-02-13 19:47:22 +00:00
|
|
|
|
e._replyNeedUid = true
|
2022-12-03 21:17:07 +00:00
|
|
|
|
return false
|
2022-09-20 11:50:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 18:17:31 +00:00
|
|
|
|
async getMysApi (e, targetType = 'all', option = {}) {
|
2022-10-21 14:48:19 +00:00
|
|
|
|
if (this.mys) {
|
|
|
|
|
return this.mys
|
|
|
|
|
}
|
2024-04-05 03:28:51 +00:00
|
|
|
|
this.mys = await e.runtime.getMysApi(targetType, option, e.isSr)
|
2022-10-21 14:48:19 +00:00
|
|
|
|
return this.mys
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 11:50:27 +00:00
|
|
|
|
async getData (api, data) {
|
2022-10-21 14:48:19 +00:00
|
|
|
|
if (!this.mysInfo) {
|
2022-09-20 11:50:27 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let e = this.e
|
2022-11-24 18:17:31 +00:00
|
|
|
|
let mys = await this.getMysApi(e, api, { log: false })
|
2023-02-22 17:48:44 +00:00
|
|
|
|
if (!mys) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-02-21 17:26:17 +00:00
|
|
|
|
let mysInfo = this.mysInfo || {}
|
2022-09-20 11:50:27 +00:00
|
|
|
|
// 暂时先在plugin侧阻止错误,防止刷屏
|
|
|
|
|
e._original_reply = e._original_reply || e.reply
|
|
|
|
|
e._reqCount = e._reqCount || 0
|
|
|
|
|
e.reply = function (msg) {
|
|
|
|
|
if (!e._isReplyed) {
|
|
|
|
|
e._isReplyed = true
|
|
|
|
|
return e._original_reply(msg)
|
|
|
|
|
} else {
|
|
|
|
|
// console.log('请求错误')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e._reqCount++
|
2022-10-21 14:48:19 +00:00
|
|
|
|
let ret = await mys.getData(api, data)
|
2023-03-01 00:38:13 +00:00
|
|
|
|
if (mysInfo && mysInfo.checkCode) {
|
|
|
|
|
ret = await mysInfo.checkCode(ret, api, this.mys)
|
|
|
|
|
}
|
2022-09-20 11:50:27 +00:00
|
|
|
|
e._reqCount--
|
|
|
|
|
if (e._reqCount === 0) {
|
|
|
|
|
e.reply = e._original_reply
|
|
|
|
|
}
|
|
|
|
|
if (!ret) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2023-02-19 21:24:17 +00:00
|
|
|
|
if (ret.retcode !== 0) {
|
|
|
|
|
e._retcode = ret.retcode
|
|
|
|
|
}
|
2022-09-20 11:50:27 +00:00
|
|
|
|
return ret.data || ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取角色信息
|
|
|
|
|
async getCharacter () {
|
|
|
|
|
return await this.getData('character')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取角色详情
|
|
|
|
|
async getAvatar (id) {
|
|
|
|
|
return await this.getData('detail', { avatar_id: id })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 首页宝箱信息
|
|
|
|
|
async getIndex () {
|
|
|
|
|
return await this.getData('index')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取深渊信息
|
|
|
|
|
async getSpiralAbyss (type = 1) {
|
|
|
|
|
return await this.getData('spiralAbyss', { schedule_type: type })
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-03 07:34:37 +00:00
|
|
|
|
// 获取幻想真境剧诗信息
|
2024-07-03 15:35:59 +00:00
|
|
|
|
async getRoleCombat (need_detail = false) {
|
|
|
|
|
return await this.getData('role_combat', { need_detail: need_detail })
|
2024-07-03 07:34:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 11:50:27 +00:00
|
|
|
|
async getDetail (id) {
|
2024-04-05 03:28:51 +00:00
|
|
|
|
if (this.e.isSr) { return await this.getData('detail', { avatar_id: id, tab_from: 'TabOwned' }) }
|
2022-09-20 11:50:27 +00:00
|
|
|
|
return await this.getData('detail', { avatar_id: id })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getCompute (data) {
|
|
|
|
|
return await this.getData('compute', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAvatarSkill (id) {
|
|
|
|
|
return await this.getData('avatarSkill', { avatar_id: id })
|
|
|
|
|
}
|
2022-09-20 12:16:19 +00:00
|
|
|
|
}
|