2023-03-07 17:52:11 +00:00
|
|
|
|
import { Common } from '#miao'
|
|
|
|
|
import { MysApi, Player, Character } from '#miao.models'
|
2023-11-05 19:18:49 +00:00
|
|
|
|
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) {
|
2023-11-05 19:18:49 +00:00
|
|
|
|
return ProfileStat.render(e, 'stat')
|
2023-02-13 20:43:14 +00:00
|
|
|
|
},
|
2023-02-18 10:29:09 +00:00
|
|
|
|
|
2023-02-13 20:43:14 +00:00
|
|
|
|
async avatarList (e) {
|
2023-11-05 19:18:49 +00:00
|
|
|
|
return ProfileStat.render(e, 'avatar')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async refreshTalent (e) {
|
|
|
|
|
let mys = await MysApi.init(e)
|
|
|
|
|
if (!mys || !mys.uid) return false
|
|
|
|
|
|
|
|
|
|
let player = Player.create(e)
|
|
|
|
|
let refreshCount = await player.refreshTalent('', 2)
|
|
|
|
|
if (refreshCount) {
|
|
|
|
|
e.reply(`角色天赋更新成功,共${refreshCount}个角色\n你现在可以通过【#练度统计】【#天赋统计】来查看角色信息了...`)
|
|
|
|
|
} else {
|
|
|
|
|
e.reply('角色天赋未能更新...')
|
|
|
|
|
}
|
2023-02-13 20:43:14 +00:00
|
|
|
|
},
|
2023-10-19 16:31:35 +00:00
|
|
|
|
|
|
|
|
|
// 渲染
|
2023-11-02 13:20:16 +00:00
|
|
|
|
// isAvatarList true:角色列表 false练度统计
|
2023-11-05 19:18:49 +00:00
|
|
|
|
async render (e, mode = 'stat') {
|
2023-02-13 20:43:14 +00:00
|
|
|
|
// 缓存时间,单位小时
|
|
|
|
|
let msg = e.msg.replace('#', '').trim()
|
|
|
|
|
if (msg === '角色统计' || msg === '武器统计') {
|
|
|
|
|
// 暂时避让一下抽卡分析的关键词
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-08-06 22:36:05 +00:00
|
|
|
|
|
2023-11-05 19:18:49 +00:00
|
|
|
|
if (/天赋|技能/.test(msg)) {
|
|
|
|
|
mode = 'talent'
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 13:20:16 +00:00
|
|
|
|
|
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
|
|
|
|
|
2023-02-13 20:43:14 +00:00
|
|
|
|
let player = Player.create(e)
|
2023-02-08 20:55:54 +00:00
|
|
|
|
|
2023-02-13 20:43:14 +00:00
|
|
|
|
let avatarRet = await player.refreshAndGetAvatarData({
|
2023-02-18 23:55:43 +00:00
|
|
|
|
index: 2,
|
2023-02-13 20:43:14 +00:00
|
|
|
|
detail: 1,
|
2023-11-05 19:18:49 +00:00
|
|
|
|
talent: mode === 'avatar' ? 0 : 1,
|
2023-02-13 20:43:14 +00:00
|
|
|
|
rank: true,
|
2023-11-05 19:18:49 +00:00
|
|
|
|
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) {
|
2023-02-21 17:26:17 +00:00
|
|
|
|
e._isReplyed || e.reply(`查询失败,暂未获得#${uid}角色数据,请绑定CK或 #更新面板`)
|
2023-02-13 20:43:14 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
2023-02-10 19:40:55 +00:00
|
|
|
|
|
2023-11-05 19:18:49 +00:00
|
|
|
|
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-11 07:24:44 +00:00
|
|
|
|
|
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
|
|
|
|
|
2023-11-05 19:18:49 +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,
|
2023-11-05 19:18:49 +00:00
|
|
|
|
mode,
|
|
|
|
|
week,
|
2023-02-19 21:24:17 +00:00
|
|
|
|
avatars: avatarRet
|
2023-02-13 20:43:14 +00:00
|
|
|
|
}, { e, scale: 1.4 })
|
2023-02-10 21:31:41 +00:00
|
|
|
|
}
|
2022-08-06 22:36:05 +00:00
|
|
|
|
}
|
2023-02-17 20:42:05 +00:00
|
|
|
|
export default ProfileStat
|