重写MysApi相关逻辑,可能会导致一些角色信息类的查询异常,如遇问题请反馈

This commit is contained in:
yoimiya-kokomi 2022-09-20 19:50:27 +08:00
parent 5583f87754
commit 78f87c9c45
21 changed files with 428 additions and 180 deletions

View File

@ -1,11 +1,13 @@
# 2.0 Alpha.4 # 2.0 Alpha.5
* `#面板练度统计` 样式由深色调整为浅色方案
* 重写MysApi相关逻辑可能会导致一些角色信息类的查询异常如遇问题请反馈
* 一些已知Bug修复
# 2.0 Alpha.1~4
* 重写`#刻晴`的角色卡片样式 * 重写`#刻晴`的角色卡片样式
* `#妮露天赋` 样式微调 * `#妮露天赋` 样式微调
* 一些已知Bug修复
# 2.0 Alpha.1~3
* `#深渊配队`、`#戳一戳` 适配V3 * `#深渊配队`、`#戳一戳` 适配V3
* 优化V3下获取Uid及CK的逻辑防止一些情况下触发报错 * 优化V3下获取Uid及CK的逻辑防止一些情况下触发报错

View File

@ -2,6 +2,7 @@ import fs from 'fs'
import lodash from 'lodash' import lodash from 'lodash'
import { exec } from 'child_process' import { exec } from 'child_process'
import { Cfg, Common, Data, App } from '../components/index.js' import { Cfg, Common, Data, App } from '../components/index.js'
import { MysApi } from '../models/index.js'
let cfgMap = { let cfgMap = {
角色: 'char.char', 角色: 'char.char',
@ -49,11 +50,12 @@ const resPath = `${_path}/plugins/miao-plugin/resources/`
const plusPath = `${resPath}/miao-res-plus/` const plusPath = `${resPath}/miao-res-plus/`
const checkAuth = async function (e) { const checkAuth = async function (e) {
return await e.checkAuth({ if (!e.isMaster) {
auth: 'master', e.reply(`只有主人才能命令喵喵哦~
replyMsg: `只有主人才能命令喵喵哦~ (*/ω*)`)
(*/ω*)` return true
}) }
return await MysApi.initUser(e)
} }
async function sysCfg (e) { async function sysCfg (e) {

View File

@ -1,4 +1,4 @@
import { Character, Avatar } from '../../models/index.js' import { Character, Avatar, MysApi } from '../../models/index.js'
import { Cfg, Common, Profile } from '../../components/index.js' import { Cfg, Common, Profile } from '../../components/index.js'
import lodash from 'lodash' import lodash from 'lodash'
import { segment } from 'oicq' import { segment } from 'oicq'
@ -11,14 +11,9 @@ export async function renderAvatar (e, avatar, renderType = 'card') {
if (!char) { if (!char) {
return false return false
} }
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all', if (!mys) return true
targetType: Cfg.get('char.queryOther', true) ? 'all' : 'self', uid = mys.uid
cookieType: 'all',
actionName: '查询信息'
})
if (!MysApi) return true
uid = MysApi.targetUser.uid
if (char.isCustom) { if (char.isCustom) {
avatar = { id: char.id, name: char.name, detail: false } avatar = { id: char.id, name: char.name, detail: false }
} else { } else {
@ -28,7 +23,7 @@ export async function renderAvatar (e, avatar, renderType = 'card') {
avatar = profile avatar = profile
} else { } else {
// 使用Mys数据兜底 // 使用Mys数据兜底
let charData = await MysApi.getCharacter() let charData = await mys.getCharacter()
if (!charData) return true if (!charData) return true
let avatars = charData.avatars let avatars = charData.avatars
@ -66,15 +61,10 @@ async function renderCard (e, ds, renderType = 'card') {
let custom = char.isCustom let custom = char.isCustom
if (!custom) { if (!custom) {
let avatar = new Avatar(ds) let avatar = new Avatar(ds)
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all',
targetType: Cfg.get('char.queryOther', true) ? 'all' : 'self',
cookieType: 'all',
actionName: '查询信息'
})
data = avatar.getData('id,name,sName,level,fetter,cons,weapon,elem,artis,artisSet,imgs,dataSourceName,updateTime') data = avatar.getData('id,name,sName,level,fetter,cons,weapon,elem,artis,artisSet,imgs,dataSourceName,updateTime')
if (avatar.isProfile || (MysApi && MysApi.isSelfCookie)) { if (avatar.isProfile || (mys && mys.isSelfCookie)) {
data.talent = await avatar.getTalent(MysApi) data.talent = await avatar.getTalent(mys)
data.talentMap = ['a', 'e', 'q'] data.talentMap = ['a', 'e', 'q']
// 计算皇冠个数 // 计算皇冠个数
data.crownNum = lodash.filter(lodash.map(data.talent, (d) => d.original), (d) => d >= 10).length data.crownNum = lodash.filter(lodash.map(data.talent, (d) => d.original), (d) => d >= 10).length
@ -101,8 +91,8 @@ async function renderCard (e, ds, renderType = 'card') {
return true return true
} }
export async function getAvatarList (e, type, MysApi) { export async function getAvatarList (e, type, mys) {
let data = await MysApi.getCharacter() let data = await mys.getCharacter()
if (!data) return false if (!data) return false
let avatars = data.avatars let avatars = data.avatars

View File

@ -1,7 +1,7 @@
// #老婆 // #老婆
import lodash from 'lodash' import lodash from 'lodash'
import { Cfg } from '../../components/index.js' import { Cfg } from '../../components/index.js'
import { Character } from '../../models/index.js' import { Character, MysApi } from '../../models/index.js'
import { getAvatarList, renderAvatar } from './avatar-card.js' import { getAvatarList, renderAvatar } from './avatar-card.js'
const relationMap = { const relationMap = {
@ -70,22 +70,12 @@ export async function wife (e) {
let avatar = {} let avatar = {}
let wifeList = [] let wifeList = []
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all', if (!mys || !mys.uid) {
targetType: Cfg.get('char.queryOther', true) ? 'all' : 'self',
cookieType: 'all',
actionName: '查询信息'
})
if (!MysApi || !MysApi.selfUser) {
return true return true
} }
let selfUser = MysApi.selfUser let selfUser = mys.selfUser
let selfMysUser = await selfUser.getMysUser()
let isSelf = true let isSelf = true
if (!selfMysUser || selfMysUser.uid !== MysApi.targetUser.uid) {
isSelf = false
}
let renderType = (action === '卡片' ? 'card' : 'photo') let renderType = (action === '卡片' ? 'card' : 'photo')
let addRet = [] let addRet = []
switch (action) { switch (action) {
@ -102,7 +92,7 @@ export async function wife (e) {
if (wifeList && wifeList.length > 0 && isSelf && !e.isPoke) { if (wifeList && wifeList.length > 0 && isSelf && !e.isPoke) {
if (wifeList[0] === '随机') { if (wifeList[0] === '随机') {
// 如果选择为全部,则从列表中随机选择一个 // 如果选择为全部,则从列表中随机选择一个
avatarList = await getAvatarList(e, targetCfg.type, MysApi) avatarList = await getAvatarList(e, targetCfg.type, mys)
let avatar = lodash.sample(avatarList) let avatar = lodash.sample(avatarList)
return renderAvatar(e, avatar, renderType) return renderAvatar(e, avatar, renderType)
} else { } else {
@ -113,13 +103,13 @@ export async function wife (e) {
} }
// 如果未指定过则从列表中排序并随机选择前5个 // 如果未指定过则从列表中排序并随机选择前5个
if (e.isPoke) { if (e.isPoke) {
avatarList = await getAvatarList(e, false, MysApi) avatarList = await getAvatarList(e, false, mys)
if (avatarList && avatarList.length > 0) { if (avatarList && avatarList.length > 0) {
avatar = lodash.sample(avatarList) avatar = lodash.sample(avatarList)
return await renderAvatar(e, avatar, renderType) return await renderAvatar(e, avatar, renderType)
} }
} else { } else {
avatarList = await getAvatarList(e, targetCfg.type, MysApi) avatarList = await getAvatarList(e, targetCfg.type, mys)
if (avatarList && avatarList.length > 0) { if (avatarList && avatarList.length > 0) {
avatar = lodash.sample(avatarList.slice(0, 5)) avatar = lodash.sample(avatarList.slice(0, 5))
return await renderAvatar(e, avatar, renderType) return await renderAvatar(e, avatar, renderType)
@ -148,12 +138,6 @@ export async function wife (e) {
} }
}) })
wifeList = lodash.filter(lodash.uniq(wifeList), (d) => !!d) wifeList = lodash.filter(lodash.uniq(wifeList), (d) => !!d)
/*
avatarList = await getAvatarList(e, targetCfg.type, MysApi);
avatarList = lodash.map(avatarList, (avatar) => avatar.name);
avatarList = lodash.filter(avatarList, (d) => !!d);
addRet = lodash.intersection(avatarList, wifeList);
*/
addRet = wifeList addRet = wifeList
if (addRet.length === 0) { if (addRet.length === 0) {
e.reply(`在可选的${targetCfg.keyword[0]}列表中未能找到 ${actionParam} ~`) e.reply(`在可选的${targetCfg.keyword[0]}列表中未能找到 ${actionParam} ~`)

View File

@ -51,17 +51,13 @@ export async function getTargetUid (e) {
} }
try { try {
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all',
targetType: 'all',
cookieType: 'all'
})
if (!MysApi || !e.targetUser) { if (!mys || !mys.uid) {
return false return false
} }
uid = e.targetUser.uid uid = mys.uid
if (!uid || !uidReg.test(uid)) { if (!uid || !uidReg.test(uid)) {
e.reply('请先发送【#绑定+你的UID】来绑定查询目标') e.reply('请先发送【#绑定+你的UID】来绑定查询目标')
return false return false

View File

@ -1,11 +1,10 @@
import lodash from 'lodash' import lodash from 'lodash'
import { autoRefresh } from './profile-common.js' import { autoRefresh } from './profile-common.js'
import { Common, Format, Profile } from '../../components/index.js' import { Common, Format, Profile } from '../../components/index.js'
import { MysApi } from '../../models/index.js'
export async function renderProfile (e, char, mode = 'profile', params = {}) { export async function renderProfile (e, char, mode = 'profile', params = {}) {
let selfUser = await e.checkAuth({ let selfUser = await MysApi.initUser(e)
auth: 'self'
})
let { uid } = e let { uid } = e

View File

@ -1,6 +1,6 @@
import lodash from 'lodash' import lodash from 'lodash'
import { Common, Profile, Data } from '../../components/index.js' import { Common, Profile, Data } from '../../components/index.js'
import { AvatarList } from '../../models/index.js' import { AvatarList, MysApi } from '../../models/index.js'
export async function profileStat (e) { export async function profileStat (e) {
// 缓存时间,单位小时 // 缓存时间,单位小时
@ -11,15 +11,11 @@ export async function profileStat (e) {
return false return false
} }
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all', if (!mys || !mys.uid) return true
targetType: 'all', let uid = mys.uid
cookieType: 'all'
})
if (!MysApi || !MysApi?.targetUser?.uid) return true
let uid = MysApi?.targetUser?.uid
let resIndex = await MysApi.getCharacter() let resIndex = await mys.getCharacter()
if (!resIndex) { if (!resIndex) {
return true return true
} }
@ -31,7 +27,7 @@ export async function profileStat (e) {
let avatars = new AvatarList(uid, resIndex.avatars) let avatars = new AvatarList(uid, resIndex.avatars)
let ids = avatars.getIds() let ids = avatars.getIds()
let talentData = await avatars.getTalentData(ids, MysApi) let talentData = await avatars.getTalentData(ids, mys)
// 天赋等级背景 // 天赋等级背景
const talentLvMap = '0,1,1,1,2,2,3,3,3,4,5'.split(',') const talentLvMap = '0,1,1,1,2,2,3,3,3,4,5'.split(',')
@ -45,7 +41,7 @@ export async function profileStat (e) {
avatarRet.push(avatar) avatarRet.push(avatar)
if (profiles[id]) { if (profiles[id]) {
let profile = profiles[id] let profile = profiles[id]
if(profile.hasData) { if (profile.hasData) {
let mark = profiles[id].getArtisMark(false) let mark = profiles[id].getArtisMark(false)
avatar.artisMark = Data.getData(mark, 'mark,markClass,names') avatar.artisMark = Data.getData(mark, 'mark,markClass,names')
} }
@ -59,7 +55,7 @@ export async function profileStat (e) {
let talentNotice = '' let talentNotice = ''
if (!MysApi.isSelfCookie) { if (!mys.isSelfCookie) {
talentNotice = '未绑定Cookie无法获取天赋列表。请回复 #体力帮助 获取配置教程' talentNotice = '未绑定Cookie无法获取天赋列表。请回复 #体力帮助 获取配置教程'
} }

View File

@ -1,4 +1,5 @@
import { segment } from 'oicq' import { segment } from 'oicq'
import { MysApi } from '../../models/index.js'
/** 获取角色卡片的原图 */ /** 获取角色卡片的原图 */
export async function getOriginalPicture (e) { export async function getOriginalPicture (e) {
@ -41,9 +42,7 @@ export async function getOriginalPicture (e) {
/* #敌人等级 */ /* #敌人等级 */
export async function enemyLv (e) { export async function enemyLv (e) {
let selfUser = await e.checkAuth({ let selfUser = await MysApi.initUser(e)
auth: 'self'
})
if (!selfUser || !e.msg) { if (!selfUser || !e.msg) {
return true return true
} }

View File

@ -3,9 +3,8 @@
* *
* */ * */
import lodash from 'lodash' import lodash from 'lodash'
import fs from 'fs'
import { Cfg, Common, App } from '../components/index.js' import { Cfg, Common, App } from '../components/index.js'
import { Abyss, AvatarList, Character } from '../models/index.js' import { Abyss, AvatarList, Character, MysApi } from '../models/index.js'
import HutaoApi from './stat/HutaoApi.js' import HutaoApi from './stat/HutaoApi.js'
let app = App.init({ let app = App.init({
@ -200,13 +199,9 @@ async function abyssPct (e) {
} }
async function abyssTeam (e) { async function abyssTeam (e) {
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e, 'cookie')
auth: 'cookie', // 所有用户均可查询
targetType: 'self', // 被查询用户可以是任意用户
cookieType: 'self' // cookie可以是任意可用cookie
})
if (!MysApi || !MysApi.selfUser || !MysApi.selfUser.uid) { if (!mys || !mys.uid) {
return true return true
} }
@ -222,7 +217,7 @@ async function abyssTeam (e) {
if (!await AvatarList.hasTalentCache(uid)) { if (!await AvatarList.hasTalentCache(uid)) {
e.reply('正在获取用户信息,请稍候...') e.reply('正在获取用户信息,请稍候...')
} }
resDetail = await MysApi.getCharacter() resDetail = await mys.getCharacter()
if (!resDetail || !resDetail.avatars || resDetail.avatars.length <= 3) { if (!resDetail || !resDetail.avatars || resDetail.avatars.length <= 3) {
e.reply('角色信息获取失败') e.reply('角色信息获取失败')
return true return true
@ -232,7 +227,7 @@ async function abyssTeam (e) {
} }
let avatars = new AvatarList(uid, resDetail.avatars) let avatars = new AvatarList(uid, resDetail.avatars)
let avatarIds = avatars.getIds() let avatarIds = avatars.getIds()
let avatarData = await avatars.getTalentData(avatarIds, MysApi) let avatarData = await avatars.getTalentData(avatarIds, mys)
let avatarRet = {} let avatarRet = {}
let data = {} let data = {}
@ -410,13 +405,8 @@ async function uploadData (e) {
if (!Cfg.get('wiki.abyss', false) && !isMatch) { if (!Cfg.get('wiki.abyss', false) && !isMatch) {
return false return false
} }
let MysApi = await e.getMysApi({ let mys = await MysApi.init(e)
auth: 'all', if (!mys || !mys.isSelfCookie) {
targetType: 'self',
cookieType: 'all',
action: '获取深渊信息'
})
if (!MysApi || !MysApi.isSelfCookie) {
if (isMatch) { if (isMatch) {
e.reply(`请绑定ck后再使用${e.original_msg || e.msg}`) e.reply(`请绑定ck后再使用${e.original_msg || e.msg}`)
} }
@ -426,11 +416,11 @@ async function uploadData (e) {
let uid = e.selfUser.uid let uid = e.selfUser.uid
let resDetail, resAbyss let resDetail, resAbyss
try { try {
resAbyss = await MysApi.getSpiralAbyss(1) resAbyss = await mys.getSpiralAbyss(1)
if (resAbyss.floors.length > 0 && !await AvatarList.hasTalentCache(uid)) { if (resAbyss.floors.length > 0 && !await AvatarList.hasTalentCache(uid)) {
e.reply('正在获取用户信息,请稍候...') e.reply('正在获取用户信息,请稍候...')
} }
resDetail = await MysApi.getCharacter() resDetail = await mys.getCharacter()
if (!resDetail || !resAbyss || !resDetail.avatars || resDetail.avatars.length <= 3) { if (!resDetail || !resAbyss || !resDetail.avatars || resDetail.avatars.length <= 3) {
e.reply('角色信息获取失败') e.reply('角色信息获取失败')
return true return true
@ -498,7 +488,7 @@ async function uploadData (e) {
} }
addMsg('最强一击', ret.data?.damage || abyssData?.stat?.dmg || {}) addMsg('最强一击', ret.data?.damage || abyssData?.stat?.dmg || {})
addMsg('最高承伤', ret.data?.takeDamage || abyssData?.stat.takeDmg || {}) addMsg('最高承伤', ret.data?.takeDamage || abyssData?.stat.takeDmg || {})
let avatarData = await avatars.getTalentData(avatarIds, MysApi) let avatarData = await avatars.getTalentData(avatarIds, mys)
return await Common.render('stat/abyss-summary', { return await Common.render('stat/abyss-summary', {
abyss: abyssData, abyss: abyssData,
avatars: avatarData, avatars: avatarData,

View File

@ -1,6 +1,5 @@
import lodash from 'lodash' import lodash from 'lodash'
import { plugin } from '../adapter/index.js' import { plugin } from '../adapter/index.js'
import { getMysApi, checkAuth } from '../adapter/mys.js'
class App { class App {
constructor (cfg) { constructor (cfg) {
@ -62,23 +61,19 @@ class App {
let e = this.e let e = this.e
if (event === 'poke') { if (event === 'poke') {
if (e.notice_type === 'group') { if (e.notice_type === 'group') {
if (e.user_id !== Bot.uin) { if (e.user_id !== Bot.uin || e.msg === '#poke#' || e.isPoke) {
return false return false
} }
// group状态下戳一戳的发起人是operator // group状态下戳一戳的发起人是operator
if (e.user_id === Bot.uin) {
e.user_id = e.operator_id e.user_id = e.operator_id
} }
}
e.isPoke = true e.isPoke = true
// 随便指定一个不太常见的msg以触发msg的正则 // 随便指定一个不太常见的msg以触发msg的正则
e.msg = '#poke#' e.msg = '#poke#'
} }
e.original_msg = e.original_msg || e.msg e.original_msg = e.original_msg || e.msg
e.checkAuth = e.checkAuth || async function (cfg) {
return await checkAuth(e, cfg)
}
e.getMysApi = e.getMysApi || async function (cfg) {
return await getMysApi(e, cfg)
}
return await app.fn.call(this, e) return await app.fn.call(this, e)
} }
} }

View File

@ -3,14 +3,6 @@ import { Version } from './index.js'
import render from './common-lib/render.js' import render from './common-lib/render.js'
export const todoV3 = function (e) {
if (Version.isV3) {
e.reply('本功能暂时不支持V3版Yunzai...')
return true
}
return false
}
function sleep (ms) { function sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms)) return new Promise((resolve) => setTimeout(resolve, ms))
} }
@ -19,6 +11,5 @@ export default {
render, render,
cfg: Cfg.get, cfg: Cfg.get,
isDisable: Cfg.isDisable, isDisable: Cfg.isDisable,
todoV3,
sleep sleep
} }

View File

@ -80,7 +80,6 @@ let Data = {
if (!/\.js$/.test(file)) { if (!/\.js$/.test(file)) {
file = file + '.js' file = file + '.js'
} }
// 检查并创建目录
if (fs.existsSync(`${root}/${file}`)) { if (fs.existsSync(`${root}/${file}`)) {
try { try {
let data = await import(`file://${root}/${file}`) let data = await import(`file://${root}/${file}`)

View File

@ -64,7 +64,7 @@ export default class AvatarList extends Base {
return rets return rets
} }
async getTalentData (ids, MysApi = false) { async getTalentData (ids, mys = false) {
let avatarTalent = await Data.getCacheJSON(`miao:avatar-talent:${this.uid}`) let avatarTalent = await Data.getCacheJSON(`miao:avatar-talent:${this.uid}`)
let needReq = {} let needReq = {}
lodash.forEach(ids, (id) => { lodash.forEach(ids, (id) => {
@ -73,14 +73,14 @@ export default class AvatarList extends Base {
} }
}) })
let needReqIds = lodash.keys(needReq) let needReqIds = lodash.keys(needReq)
if (needReqIds.length > 0 && MysApi && MysApi.isSelfCookie) { if (needReqIds.length > 0 && mys && mys.isSelfCookie) {
let num = 10 let num = 10
let ms = 100 let ms = 100
let skillRet = [] let skillRet = []
let avatarArr = lodash.chunk(needReqIds, num) let avatarArr = lodash.chunk(needReqIds, num)
for (let val of avatarArr) { for (let val of avatarArr) {
for (let id of val) { for (let id of val) {
skillRet.push(this.getAvatarTalent(id, MysApi)) skillRet.push(this.getAvatarTalent(id, mys))
} }
skillRet = await Promise.all(skillRet) skillRet = await Promise.all(skillRet)
skillRet = skillRet.filter(item => item.id) skillRet = skillRet.filter(item => item.id)
@ -93,14 +93,14 @@ export default class AvatarList extends Base {
} }
let ret = this.getData(ids) let ret = this.getData(ids)
lodash.forEach(ret, (avatar, id) => { lodash.forEach(ret, (avatar, id) => {
avatar.talent = avatarTalent[id] || { a: {}, e: {}, q: {} } avatar.talent = avatarTalent[id] || {}
}) })
return ret return ret
} }
async getAvatarTalent (id, MysApi) { async getAvatarTalent (id, mys) {
let talent = {} let talent = {}
let talentRes = await MysApi.getDetail(id) let talentRes = await mys.getDetail(id)
let char = Character.get(id) let char = Character.get(id)
let avatar = this.avatars[id] let avatar = this.avatars[id]
if (!char || !avatar) { if (!char || !avatar) {

127
models/MysApi.js Normal file
View File

@ -0,0 +1,127 @@
import { User } from './index.js'
import MysInfo from './mys-lib/MysInfo.js'
export default class MysApi {
constructor (e, uid, MysApi) {
this.e = e
this.MysApi = MysApi
this.ckInfo = MysApi.ckInfo
this.uid = uid
e.targetUser = this.targetUser
e.selfUser = this.selfUser
e.isSelfCookie = this.isSelfCookie
}
static async init (e, cfg = 'all') {
if (typeof (cfg) === 'string') {
cfg = { auth: cfg }
}
let { auth = 'all' } = cfg
let mys = await MysInfo.init(e, 'roleIndex')
if (!mys) {
return false
}
let uid = mys.uid
let ckUid = mys.ckInfo?.uid
/* 检查user ck */
if (auth === 'cookie') {
let isCookieUser = await MysInfo.checkUidBing(uid)
if (!isCookieUser || uid !== ckUid) {
e.reply('尚未绑定Cookie...')
return false
}
}
return new MysApi(e, uid, mys)
}
static async initUser (e, cfg = 'all') {
if (typeof (cfg) === 'string') {
cfg = { auth: cfg }
}
let uid = await MysInfo.getUid(e)
if (uid) {
return new User({ id: e.user_id, uid: uid })
}
return false
}
get isSelfCookie () {
return this.uid * 1 === this.ckUid * 1
}
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 })
}
async getData (api, data) {
if (!this.MysApi) {
return false
}
let e = this.e
// 暂时先在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++
let ret = await MysInfo.get(this.e, api, data)
e._reqCount--
if (e._reqCount === 0) {
e.reply = e._original_reply
}
if (!ret) {
return false
}
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 })
}
async getDetail (id) {
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 })
}
}

65
models/User.js Normal file
View File

@ -0,0 +1,65 @@
/*
* User Class
* 提供用户实例相关的操作方法
* */
import Base from './Base.js'
import lodash from 'lodash'
/* User Class Model
* 所有用户实例均可调用实例方法
* */
class User extends Base {
// 初始化用户
constructor (cfg) {
super()
let self = this._getCache(`user:${cfg.id}`)
if (!self) {
self = this
}
self.uid = cfg.uid || self.uid || ''
self.ck = cfg.ck || cfg.cookie || self.ck || ''
return self._cache()
}
// 保存用户配置
async setCfg (path, value) {
let userCfg = await redis.get(`miao:user-cfg:${this.id}`) || await redis.get(`genshin:user-cfg:${this.id}`)
userCfg = userCfg ? JSON.parse(userCfg) : {}
lodash.set(userCfg, path, value)
await redis.set(`miao:user-cfg:${this.id}`, JSON.stringify(userCfg))
}
/* 获取用户配置 */
async getCfg (path, defaultValue) {
let userCfg = await redis.get(`miao:user-cfg:${this.id}`) || await redis.get(`genshin:user-cfg:${this.id}`)
userCfg = userCfg ? JSON.parse(userCfg) : {}
return lodash.get(userCfg, path, defaultValue)
}
async getMysUser () {
return {
uid: this.uid
}
}
get cookie () {
return this.ck || ''
}
static async get (e) {
if (e.user_id) {
return new User({ id: e.user_id })
}
}
static async checkAuth (e, type = 'all') {
let user = await User.get(e)
if (type === 'master') {
return false
}
return user
}
}
export default User

View File

@ -11,6 +11,8 @@ import ProfileArtis from './ProfileArtis.js'
import ProfileDmg from './ProfileDmg.js' import ProfileDmg from './ProfileDmg.js'
import Material from './Material.js' import Material from './Material.js'
import Weapon from './Weapon.js' import Weapon from './Weapon.js'
import User from './User.js'
import MysApi from './MysApi.js'
export { export {
Base, Base,
@ -25,5 +27,7 @@ export {
ProfileArtis, ProfileArtis,
ProfileDmg, ProfileDmg,
Material, Material,
Weapon Weapon,
User,
MysApi
} }

62
models/mys-lib/MysInfo.js Normal file
View File

@ -0,0 +1,62 @@
import { Data } from '../../components/index.js'
let MysInfo = false
async function init () {
let mys = await Data.importModule('plugins/genshin/model/mys/mysInfo.js', 'root')
if (mys && mys.default) {
MysInfo = mys.default
}
}
await init()
if (!MysInfo) {
// v2 MysInfo
const apiCfg = {
auth: 'all',
targetType: 'all',
cookieType: 'all',
}
MysInfo = 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) {
let MysApi = await e.getMysApi(apiCfg) // V2兼容
let { targetUser, cookieUser } = MysApi
let mys = new MysInfo(e, targetUser.id, cookieUser)
mys._MysApi = MysApi
return mys
}
// 检查当前UID是否有CK绑定
static async checkUidBing (uid) {
}
static async getUid (e) {
}
static async getData (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

View File

@ -61,6 +61,13 @@
.cont { .cont {
font-size: 14px; font-size: 14px;
background: none; background: none;
/*
.star(1, rgba(171, 171, 171, .5));
.star(2, rgba(208, 255, 190, .5));
.star(3, rgba(190, 208, 255, .5));
.star(4, rgba(223, 190, 255, .5));
.star(5, rgba(255, 228, 180, .5));
*/
} }
.cont .item-name { .cont .item-name {
padding-left: 5px; padding-left: 5px;
@ -90,19 +97,19 @@
box-shadow: 0 0 1px 0 rgba(100, 100, 100, 0.5) inset; box-shadow: 0 0 1px 0 rgba(100, 100, 100, 0.5) inset;
} }
.cont .tr .td.star1 { .cont .tr .td.star1 {
background: rgba(171, 171, 171, 0.8); background: rgba(171, 171, 171, 0.5);
} }
.cont .tr .td.star2 { .cont .tr .td.star2 {
background: rgba(208, 255, 190, 0.8); background: rgba(208, 255, 190, 0.5);
} }
.cont .tr .td.star3 { .cont .tr .td.star3 {
background: rgba(190, 208, 255, 0.8); background: rgba(190, 208, 255, 0.5);
} }
.cont .tr .td.star4 { .cont .tr .td.star4 {
background: rgba(223, 190, 255, 0.8); background: rgba(223, 190, 255, 0.5);
} }
.cont .tr .td.star5 { .cont .tr .td.star5 {
background: rgba(255, 228, 180, 0.8); background: rgba(255, 228, 180, 0.5);
} }
.cont .tr.thead { .cont .tr.thead {
background: rgba(0, 0, 0, 0.5) !important; background: rgba(0, 0, 0, 0.5) !important;
@ -111,10 +118,10 @@
color: #d3bc8e !important; color: #d3bc8e !important;
} }
.cont .tr:nth-child(odd) { .cont .tr:nth-child(odd) {
background: rgba(255, 255, 255, 0.95); background: #fff;
} }
.cont .tr:nth-child(even) { .cont .tr:nth-child(even) {
background: rgba(210, 210, 210, 0.95); background: #f0f0f0;
} }
.cont .tr > div { .cont .tr > div {
text-align: center; text-align: center;
@ -235,6 +242,40 @@
width: 115px; width: 115px;
text-align: left; text-align: left;
} }
.cont .td-artis.class-ACE,
.cont .td-artis.class-ACE² {
background: rgba(255, 228, 180, 0.5);
}
.cont .td-artis.class-ACE .artis-mark-class,
.cont .td-artis.class-ACE² .artis-mark-class {
background: #ff5722;
}
.cont .td-artis.class-SSS,
.cont .td-artis.class-SS {
background: rgba(223, 190, 255, 0.5);
}
.cont .td-artis.class-SSS .artis-mark-class,
.cont .td-artis.class-SS .artis-mark-class {
background: #531ba9cf;
}
.cont .td-artis.class-S,
.cont .td-artis.class-A {
background: rgba(190, 208, 255, 0.5);
}
.cont .td-artis.class-S .artis-mark-class,
.cont .td-artis.class-A .artis-mark-class {
background: #3955b7;
}
.cont .td-artis.class-B,
.cont .td-artis.class-C,
.cont .td-artis.class-D {
background: rgba(171, 171, 171, 0.5);
}
.cont .td-artis.class-B .artis-mark-class,
.cont .td-artis.class-C .artis-mark-class,
.cont .td-artis.class-D .artis-mark-class {
background: #aaa;
}
.cont .avatar-artis { .cont .avatar-artis {
margin-left: 5px; margin-left: 5px;
text-align: left; text-align: left;
@ -271,7 +312,7 @@
.cont .artis-mark-class { .cont .artis-mark-class {
width: 28px; width: 28px;
font-size: 12px; font-size: 12px;
border-radius: 3px; border-radius: 5px;
display: inline-block; display: inline-block;
text-align: center; text-align: center;
background: rgba(51, 51, 51, 0.68); background: rgba(51, 51, 51, 0.68);
@ -284,23 +325,6 @@
transform: scale(0.7); transform: scale(0.7);
color: #fff; color: #fff;
} }
.cont .artis-mark-class.class-ACE,
.cont .artis-mark-class.class-ACE² {
background: #ff5722;
}
.cont .artis-mark-class.class-SSS,
.cont .artis-mark-class.class-SS {
background: #531ba9cf;
}
.cont .artis-mark-class.class-S,
.cont .artis-mark-class.class-A {
background: #3955b7;
}
.cont .artis-mark-class.class-B,
.cont .artis-mark-class.class-C,
.cont .artis-mark-class.class-D {
background: #aaa;
}
.cont .artis-na { .cont .artis-na {
padding-left: 13px; padding-left: 13px;
white-space: nowrap; white-space: nowrap;

View File

@ -41,8 +41,8 @@
<span class="item-name">{{avatar.abbr||avatar.name}}</span> <span class="item-name">{{avatar.abbr||avatar.name}}</span>
</div> </div>
</div> </div>
<div class="td td-lv">{{avatar.level}}</div> <div class="td td-lv star{{avatar.star}}">{{avatar.level}}</div>
<div class="td td-cons"> <div class="td td-cons star{{avatar.star}}">
<span class="cons avatar cons-{{avatar.cons}}">{{avatar.cons}}</span> <span class="cons avatar cons-{{avatar.cons}}">{{avatar.cons}}</span>
</div> </div>
<div class="td td-fetter"> <div class="td td-fetter">
@ -71,7 +71,7 @@
{{/if}} {{/if}}
</div> </div>
{{set mark = avatar.artisMark || false }} {{set mark = avatar.artisMark || false }}
<div class="td td-artis"> <div class="td td-artis class-{{mark?.markClass||'D'}}">
<div class="item item-banner avatar-artis artis{{avatar?.artisMark?.names?.length||avatar.names.length}}"> <div class="item item-banner avatar-artis artis{{avatar?.artisMark?.names?.length||avatar.names.length}}">
{{set names = avatar?.artisMark?.names || avatar?.names || []}} {{set names = avatar?.artisMark?.names || avatar?.names || []}}
<div class="artis item-icon {{names.length>0?'star5':'no-artis'}}"> <div class="artis item-icon {{names.length>0?'star5':'no-artis'}}">

View File

@ -113,11 +113,11 @@
background: @color; background: @color;
} }
} }
.star(1, rgba(171, 171, 171, .8)); .star(1, rgba(171, 171, 171, .5));
.star(2, rgba(208, 255, 190, .8)); .star(2, rgba(208, 255, 190, .5));
.star(3, rgba(190, 208, 255, .8)); .star(3, rgba(190, 208, 255, .5));
.star(4, rgba(223, 190, 255, .8)); .star(4, rgba(223, 190, 255, .5));
.star(5, rgba(255, 228, 180, .8)); .star(5, rgba(255, 228, 180, .5));
&.thead { &.thead {
background: rgba(0, 0, 0, 0.5) !important; background: rgba(0, 0, 0, 0.5) !important;
@ -128,11 +128,11 @@
} }
&:nth-child(odd) { &:nth-child(odd) {
background: rgba(255, 255, 255, .95) background: #fff;
} }
&:nth-child(even) { &:nth-child(even) {
background: rgba(210, 210, 210, .95) background: #f0f0f0;
} }
& > div { & > div {
@ -272,9 +272,51 @@
} }
/*
.star(1, rgba(171, 171, 171, .5));
.star(2, rgba(208, 255, 190, .5));
.star(3, rgba(190, 208, 255, .5));
.star(4, rgba(223, 190, 255, .5));
.star(5, rgba(255, 228, 180, .5));
*/
.td-artis { .td-artis {
width: 115px; width: 115px;
text-align: left; text-align: left;
&.class- {
&ACE, &ACE² {
background: rgba(255, 228, 180, .5);
.artis-mark-class {
background: #ff5722;
}
}
&SSS, &SS {
background: rgba(223, 190, 255, .5);
.artis-mark-class {
background: #531ba9cf;
}
}
&S, &A {
background: rgba(190, 208, 255, .5);
.artis-mark-class {
background: #3955b7;
}
}
&B, &C, &D {
background: rgba(171, 171, 171, .5);
.artis-mark-class {
background: #aaa;
}
}
}
} }
.avatar-artis { .avatar-artis {
@ -324,7 +366,7 @@
.artis-mark-class { .artis-mark-class {
width: 28px; width: 28px;
font-size: 12px; font-size: 12px;
border-radius: 3px; border-radius: 5px;
display: inline-block; display: inline-block;
text-align: center; text-align: center;
background: rgba(51, 51, 51, 0.68); background: rgba(51, 51, 51, 0.68);
@ -337,26 +379,7 @@
transform: scale(.7); transform: scale(.7);
color: #fff; color: #fff;
&.class- {
&ACE,
&ACE² {
background: #ff5722;
}
&SSS,
&SS {
background: #531ba9cf;
}
&S,
&A {
background: #3955b7;
}
&B, &C, &D {
background: #aaa;
}
}
} }
.artis-na { .artis-na {

View File

@ -13,7 +13,7 @@
<div class="avatar-level">Lv{{avatar.level}}</div> <div class="avatar-level">Lv{{avatar.level}}</div>
</div> </div>
{{set talent = avatar.talent || {} }} {{set talent = avatar.talent || {} }}
{{if talent.a && talent.a.level && false }} {{if talent.a && talent.a.level }}
<div class="avatar-talent"> <div class="avatar-talent">
{{each talentMap k}} {{each talentMap k}}
{{set t = talent[k] || {} }} {{set t = talent[k] || {} }}