miao-plugin/apps/character/ProfileList.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

import lodash from 'lodash'
2022-10-06 22:20:46 +00:00
import { autoRefresh, getTargetUid } from './ProfileCommon.js'
2022-11-07 20:08:24 +00:00
import { ProfileRank } from '../../models/index.js'
import { Common, Profile, Data } from '../../components/index.js'
export async function profileList (e) {
let uid = await getTargetUid(e)
if (!uid) {
return true
}
2022-11-07 20:08:24 +00:00
let rank = false
if (e.group_id) {
rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id })
}
let servName = Profile.getServName(uid)
let hasNew = false
let newCount = 0
let chars = []
let msg = ''
let newChar = {}
if (e.newChar) {
msg = '获取角色面板数据成功'
newChar = e.newChar
}
2022-11-07 20:08:24 +00:00
const cfg = await Data.importCfg('cfg')
const groupRank = cfg?.diyCfg?.groupRank || false
await Profile.forEach(uid, async function (profile) {
2022-08-18 10:13:42 +00:00
if (!profile.hasData) {
return true
}
2022-08-18 10:13:42 +00:00
let char = profile.char
let tmp = char.getData('id,face,name,abbr,element,star')
tmp.face = char.getImgs(profile.costume).face
2022-08-18 10:13:42 +00:00
tmp.source = profile.dataSource
tmp.level = profile.level || 1
tmp.cons = profile.cons
tmp.isNew = 0
2022-11-07 20:08:24 +00:00
if (rank) {
tmp.groupRank = await rank.getRank(profile)
}
if (newChar[char.name]) {
tmp.isNew = 1
newCount++
}
chars.push(tmp)
})
if (chars.length === 0) {
if (await autoRefresh(e)) {
await profileList(e)
return true
} else {
e.reply('尚未获取任何角色数据')
}
return true
}
if (newCount > 0) {
hasNew = newCount <= 8
}
chars = lodash.sortBy(chars, ['isNew', 'star', 'level', 'id'])
chars = chars.reverse()
// 渲染图像
return await Common.render('character/profile-list', {
save_id: uid,
uid,
chars,
servName,
hasNew,
2022-11-07 20:08:24 +00:00
msg,
groupRank
}, { e, scale: 1.6 })
}