2022-08-05 22:12:57 +00:00
|
|
|
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'
|
2022-08-05 22:12:57 +00:00
|
|
|
|
2022-08-24 01:07:06 +00:00
|
|
|
export async function profileList (e) {
|
2022-08-05 22:12:57 +00:00
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
if (!uid) {
|
|
|
|
return true
|
|
|
|
}
|
2022-11-13 20:43:59 +00:00
|
|
|
let isSelfUid = false
|
|
|
|
if (e.runtime) {
|
|
|
|
let uids = e.runtime?.user?.ckUids || []
|
|
|
|
isSelfUid = uids.join(',').split(',').includes(uid + '')
|
|
|
|
}
|
2022-11-07 20:08:24 +00:00
|
|
|
let rank = false
|
2022-08-08 21:16:37 +00:00
|
|
|
let servName = Profile.getServName(uid)
|
|
|
|
let hasNew = false
|
|
|
|
let newCount = 0
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
|
|
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')
|
2022-11-13 19:42:24 +00:00
|
|
|
// 获取面板数据
|
|
|
|
let profiles = Profile.getAll(uid)
|
|
|
|
// 检测标志位
|
2022-11-17 19:40:32 +00:00
|
|
|
let qq = (e.at && !e.atBot) ? e.at : e.qq
|
|
|
|
await ProfileRank.setUidInfo({ uid, profiles, qq, uidType: isSelfUid ? 'ck' : 'bind' })
|
2022-11-13 19:42:24 +00:00
|
|
|
|
|
|
|
let groupId = e.group_id
|
|
|
|
if (groupId) {
|
|
|
|
rank = await ProfileRank.create({ groupId, uid, qq: e.user_id })
|
|
|
|
}
|
2022-11-09 21:25:19 +00:00
|
|
|
const groupRank = rank && (cfg?.diyCfg?.groupRank || false)
|
2022-11-09 19:48:13 +00:00
|
|
|
const rankCfg = await ProfileRank.getGroupCfg(groupId)
|
2022-11-07 20:08:24 +00:00
|
|
|
await Profile.forEach(uid, async function (profile) {
|
2022-08-18 10:13:42 +00:00
|
|
|
if (!profile.hasData) {
|
2022-09-30 12:20:04 +00:00
|
|
|
return true
|
2022-08-05 22:12:57 +00:00
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
let char = profile.char
|
2022-09-03 21:08:57 +00:00
|
|
|
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
|
2022-10-20 18:42:30 +00:00
|
|
|
tmp.cons = profile.cons
|
2022-08-10 18:12:48 +00:00
|
|
|
tmp.isNew = 0
|
2022-08-08 21:16:37 +00:00
|
|
|
if (newChar[char.name]) {
|
|
|
|
tmp.isNew = 1
|
|
|
|
newCount++
|
|
|
|
}
|
2022-11-09 02:44:05 +00:00
|
|
|
if (rank) {
|
|
|
|
tmp.groupRank = await rank.getRank(profile, !!tmp.isNew)
|
|
|
|
}
|
2022-08-05 22:12:57 +00:00
|
|
|
chars.push(tmp)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (chars.length === 0) {
|
|
|
|
if (await autoRefresh(e)) {
|
2022-08-24 01:07:06 +00:00
|
|
|
await profileList(e)
|
2022-08-05 22:12:57 +00:00
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
e.reply('尚未获取任何角色数据')
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-08-08 21:16:37 +00:00
|
|
|
if (newCount > 0) {
|
|
|
|
hasNew = newCount <= 8
|
|
|
|
}
|
|
|
|
|
2022-08-05 22:12:57 +00:00
|
|
|
chars = lodash.sortBy(chars, ['isNew', 'star', 'level', 'id'])
|
|
|
|
chars = chars.reverse()
|
|
|
|
|
|
|
|
// 渲染图像
|
|
|
|
return await Common.render('character/profile-list', {
|
|
|
|
save_id: uid,
|
|
|
|
uid,
|
|
|
|
chars,
|
2022-08-08 21:16:37 +00:00
|
|
|
servName,
|
|
|
|
hasNew,
|
2022-11-07 20:08:24 +00:00
|
|
|
msg,
|
2022-11-09 19:48:13 +00:00
|
|
|
groupRank,
|
2022-11-13 19:42:24 +00:00
|
|
|
allowRank: rank && rank.allowRank,
|
2022-11-09 19:48:13 +00:00
|
|
|
rankCfg
|
2022-08-24 01:07:06 +00:00
|
|
|
}, { e, scale: 1.6 })
|
2022-08-05 22:12:57 +00:00
|
|
|
}
|