miao-plugin/apps/profile/ProfileStat.js

139 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-03-07 17:52:11 +00:00
import { Common } from '#miao'
import { MysApi, Player, Character } from '#miao.models'
import moment from 'moment'
import lodash from 'lodash'
2022-08-06 22:36:05 +00:00
2023-02-13 20:43:14 +00:00
const ProfileStat = {
async stat (e) {
return ProfileStat.render(e, 'stat')
2023-02-13 20:43:14 +00:00
},
2023-02-13 20:43:14 +00:00
async avatarList (e) {
return ProfileStat.render(e, 'avatar')
},
async refreshTalent (e) {
let game = /星铁/.test(e.msg) ? 'sr' : 'gs'
e.isSr = game === 'sr'
let mys = await MysApi.init(e)
if (!mys || !mys.uid) return false
let player = Player.create(e, game)
let refreshCount = await player.refreshTalent('', 2)
if (refreshCount && !e.isSr) {
e.reply(`角色天赋更新成功,共${refreshCount}个角色\n你现在可以通过【#练度统计】【#天赋统计】来查看角色信息了...`)
} else if (e.isSr) {
e.reply(`角色天赋更新成功,共${refreshCount}个角色\n你现在可以通过【*练度统计】来查看角色信息了...`)
} else {
e.reply('角色天赋未能更新...')
}
2023-02-13 20:43:14 +00:00
},
2023-10-19 16:31:35 +00:00
// 渲染
// mode stat:练度统计 avatar:角色列表 talent:天赋统计
async render (e, mode = 'stat') {
let game = /星铁/.test(e.msg) ? 'sr' : 'gs'
e.isSr = game === 'sr'
e.game = game
2023-02-13 20:43:14 +00:00
// 缓存时间,单位小时
let msg = e.msg.replace(/#星铁|#/, '').trim()
2023-02-13 20:43:14 +00:00
if (msg === '角色统计' || msg === '武器统计') {
// 暂时避让一下抽卡分析的关键词
return false
}
2022-08-06 22:36:05 +00:00
if (/天赋|技能/.test(msg)) {
mode = 'talent'
}
2023-02-13 20:43:14 +00:00
let mys = await MysApi.init(e)
if (!mys || !mys.uid) return false
2022-08-06 22:36:05 +00:00
2023-02-13 20:43:14 +00:00
const uid = mys.uid
2023-02-10 14:01:18 +00:00
let player = Player.create(e, game)
2023-02-08 20:55:54 +00:00
2023-02-13 20:43:14 +00:00
let avatarRet = await player.refreshAndGetAvatarData({
index: 2,
2023-02-13 20:43:14 +00:00
detail: 1,
talent: mode === 'avatar' ? 0 : 1,
2023-02-13 20:43:14 +00:00
rank: true,
materials: mode === 'talent',
2023-02-13 20:43:14 +00:00
retType: 'array',
sort: true
})
2023-02-08 20:55:54 +00:00
2023-02-13 20:43:14 +00:00
if (avatarRet.length === 0) {
e._isReplyed || e.reply(`查询失败,暂未获得#${uid}角色数据请绑定CK或 #更新面板`)
2023-02-13 20:43:14 +00:00
return true
}
let starFilter = 0
if (/(五|四|5|4|)+星/.test(msg)) {
starFilter = /(五|5)+星/.test(msg) ? 5 : 4
}
if (starFilter) {
avatarRet = lodash.filter(avatarRet, ds => ds.star === starFilter)
}
let now = moment(new Date())
if (now.hour() < 4) {
now = now.add(-1, 'days')
}
let week = now.weekday()
if (mode === 'talent') {
let weekRet = /周([1-6]|一|二|三|四|五|六)/.exec(msg)
let weekSel = weekRet?.[1]
if (/(今日|今天)/.test(msg)) {
weekSel = week + 1
} else if (/(明天|明日)/.test(msg)) {
now = now.add(1, 'days')
weekSel = now.weekday() + 1
}
let weekFilter = (weekSel * 1) || ('一二三四五六'.split('').indexOf(weekSel) + 1)
if (weekFilter && weekFilter !== 7) {
avatarRet = lodash.filter(avatarRet, ds => ds?.materials?.talent?.num === ['周一/周四', '周二/周五', '周三/周六'][(weekFilter - 1) % 3])
}
}
let faceChar = Character.get(player.face) || Character.get(avatarRet[0]?.id)
2023-02-19 02:38:51 +00:00
let imgs = faceChar.imgs
2023-02-13 20:43:14 +00:00
let face = {
2023-02-19 02:38:51 +00:00
banner: imgs?.banner,
face: imgs?.face,
qFace: imgs?.qFace,
2023-02-13 20:43:14 +00:00
name: player.name || `#${uid}`,
sign: player.sign,
level: player.level
}
2023-02-13 20:43:14 +00:00
let info = player.getInfo()
info.stats = info.stats || {}
info.statMap = {
achievement: '成就',
wayPoint: '锚点',
avatar: '角色',
avatar5: '五星角色',
goldCount: '金卡总数'
}
2022-08-06 22:36:05 +00:00
let tpl = mode === 'avatar' ? 'character/avatar-list' : 'character/profile-stat'
return await Common.render(tpl, {
2023-02-13 20:43:14 +00:00
save_id: uid,
uid,
info,
updateTime: player.getUpdateTime(),
isSelfCookie: e.isSelfCookie,
face,
mode,
week,
avatars: avatarRet,
game
2023-02-13 20:43:14 +00:00
}, { e, scale: 1.4 })
}
2022-08-06 22:36:05 +00:00
}
export default ProfileStat