miao-plugin/apps/profile/ProfileStat.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-08-06 22:36:05 +00:00
import lodash from 'lodash'
import {Cfg, Common, Data } from '../../components/index.js'
2022-11-07 20:16:30 +00:00
import { AvatarList, ProfileRank } from '../../models/index.js'
2022-08-06 22:36:05 +00:00
export async function profileStat (e) {
let isMatch = /^#(喵喵|面板)练度统计?$/.test(e.original_msg || e.msg || '')
if (!Cfg.get('profileStat', false) && !isMatch) {
return false
}
2022-08-06 22:36:05 +00:00
// 缓存时间,单位小时
let msg = e.msg.replace('#', '').trim()
if (msg === '角色统计' || msg === '武器统计') {
// 暂时避让一下抽卡分析的关键词
return false
}
let avatars = await AvatarList.getAll(e)
if (!avatars) {
2022-08-06 22:36:05 +00:00
return true
}
let uid = avatars.uid
2022-11-07 20:16:30 +00:00
let rank = false
if (e.group_id) {
rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id })
}
let talentData = await avatars.getTalentData()
2022-08-06 22:36:05 +00:00
// 天赋等级背景
let avatarRet = []
lodash.forEach(talentData, (avatar) => {
2022-08-18 10:13:42 +00:00
let { talent, id } = avatar
2022-08-06 22:36:05 +00:00
avatar.aeq = talent?.a?.original + talent?.e?.original + talent?.q?.original || 3
avatarRet.push(avatar)
let profile = avatars.getProfile(id)
if (profile) {
if (profile.hasData) {
let mark = profile.getArtisMark(false)
avatar.artisMark = Data.getData(mark, 'mark,markClass,names')
2022-11-07 20:16:30 +00:00
if (rank) {
rank.getRank(profile)
}
}
}
2022-08-06 22:36:05 +00:00
})
let sortKey = 'level,star,aeq,cons,weapon.level,weapon.star,weapon.affix,fetter'.split(',')
avatarRet = lodash.orderBy(avatarRet, sortKey)
avatarRet = avatarRet.reverse()
let talentNotice = ''
if (!avatars.isSelfCookie || avatarRet.length <= 8) {
talentNotice = '未绑定CK信息可能展示不完全。回复<span>#体力帮助</span>获取CK配置帮助'
2022-08-06 22:36:05 +00:00
}
return await Common.render('character/profile-stat', {
save_id: uid,
uid,
talentLvMap: '0,1,1,1,2,2,3,3,3,4,5'.split(','),
2022-08-06 22:36:05 +00:00
avatars: avatarRet,
isSelf: e.isSelf,
talentNotice
}, { e, scale: 1.8 })
2022-08-06 22:36:05 +00:00
}