2022-08-05 22:12:57 +00:00
|
|
|
|
import lodash from 'lodash'
|
2023-02-13 19:47:22 +00:00
|
|
|
|
import { getTargetUid } from './ProfileCommon.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
|
import { Common, Data } from '#miao'
|
2024-02-04 01:27:34 +00:00
|
|
|
|
import { Button, ProfileRank, Player, Character } from '#miao.models'
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
const ProfileList = {
|
2023-02-17 20:42:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* 刷新面板
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns {Promise<boolean|*>}
|
|
|
|
|
*/
|
2024-02-04 01:27:34 +00:00
|
|
|
|
async refresh (e) {
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
|
if (!uid) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e._replyNeedUid || e.reply(['请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】', new Button(e).bindUid()])
|
2023-02-13 19:47:22 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
// 数据更新
|
|
|
|
|
let player = Player.create(e)
|
|
|
|
|
await player.refreshProfile(2)
|
2022-11-13 19:42:24 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
if (!player?._update?.length) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e._isReplyed || e.reply(['获取角色面板数据失败,请确认角色已在游戏内橱窗展示,并开放了查看详情。设置完毕后请5分钟后再进行请求~', new Button(e).profileList(uid)])
|
2023-02-19 02:53:51 +00:00
|
|
|
|
e._isReplyed = true
|
2023-02-13 19:47:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
let ret = {}
|
|
|
|
|
lodash.forEach(player._update, (id) => {
|
|
|
|
|
let char = Character.get(id)
|
|
|
|
|
if (char) {
|
|
|
|
|
ret[char.name] = true
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-03-21 19:03:01 +00:00
|
|
|
|
if (lodash.isEmpty(ret)) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e._isReplyed || e.reply(['获取角色面板数据失败,未能请求到角色数据。请确认角色已在游戏内橱窗展示,并开放了查看详情。设置完毕后请5分钟后再进行请求~', new Button(e).profileList(uid)])
|
2023-02-19 02:53:51 +00:00
|
|
|
|
e._isReplyed = true
|
2023-02-13 19:47:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
e.newChar = ret
|
|
|
|
|
return await ProfileList.render(e)
|
|
|
|
|
}
|
2022-08-05 22:12:57 +00:00
|
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
|
return true
|
|
|
|
|
},
|
2023-02-17 20:42:05 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 渲染面板
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns {Promise<boolean|*>}
|
|
|
|
|
*/
|
|
|
|
|
|
2024-02-04 01:27:34 +00:00
|
|
|
|
async render (e) {
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
|
if (!uid) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e._replyNeedUid || e.reply(['请先发送【#绑定+你的UID】来绑定查询目标\n星铁请使用【#星铁绑定+UID】', new Button(e).bindUid()])
|
2023-02-13 19:47:22 +00:00
|
|
|
|
return true
|
2022-08-08 21:16:37 +00:00
|
|
|
|
}
|
2023-03-31 20:03:05 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let isSelfUid = false
|
2023-12-11 19:16:03 +00:00
|
|
|
|
if (e.runtime && e.runtime?.user) {
|
|
|
|
|
let uids = []
|
|
|
|
|
let user = e.runtime.user
|
|
|
|
|
if (typeof user.getCkUidList === 'function') {
|
|
|
|
|
uids = user.getCkUidList(e.game).map(i => i.uid) || []
|
|
|
|
|
} else {
|
|
|
|
|
uids = user.ckUids || []
|
|
|
|
|
}
|
|
|
|
|
isSelfUid = uids.some(ds => ds === uid + '')
|
2022-11-09 02:44:05 +00:00
|
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let rank = false
|
2023-05-16 05:04:43 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let hasNew = false
|
|
|
|
|
let newCount = 0
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let chars = []
|
|
|
|
|
let msg = ''
|
|
|
|
|
let newChar = {}
|
|
|
|
|
if (e.newChar) {
|
|
|
|
|
msg = '获取角色面板数据成功'
|
|
|
|
|
newChar = e.newChar
|
|
|
|
|
}
|
|
|
|
|
const cfg = await Data.importCfg('cfg')
|
|
|
|
|
// 获取面板数据
|
|
|
|
|
let player = Player.create(e)
|
2023-05-16 05:04:43 +00:00
|
|
|
|
let servName = Player.getProfileServName(uid, player.game)
|
2023-02-13 19:47:22 +00:00
|
|
|
|
if (!player.hasProfile) {
|
|
|
|
|
await player.refresh({ profile: true })
|
|
|
|
|
}
|
|
|
|
|
if (!player.hasProfile) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`本地暂无uid${uid}[${player.game}]的面板数据...`, new Button(e).profileList(uid)])
|
2023-02-13 19:47:22 +00:00
|
|
|
|
return true
|
2022-08-05 22:12:57 +00:00
|
|
|
|
}
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let profiles = player.getProfiles()
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
// 检测标志位
|
2023-03-13 07:28:40 +00:00
|
|
|
|
let qq = (e.at && !e.atBot) ? e.at : e.user_id
|
2023-02-13 19:47:22 +00:00
|
|
|
|
await ProfileRank.setUidInfo({ uid, profiles, qq, uidType: isSelfUid ? 'ck' : 'bind' })
|
2022-08-08 21:16:37 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (groupId) {
|
|
|
|
|
rank = await ProfileRank.create({ groupId, uid, qq: e.user_id })
|
|
|
|
|
}
|
|
|
|
|
const rankCfg = await ProfileRank.getGroupCfg(groupId)
|
|
|
|
|
const groupRank = rank && (cfg?.diyCfg?.groupRank || false) && rankCfg.status !== 1
|
|
|
|
|
for (let id in profiles) {
|
|
|
|
|
let profile = profiles[id]
|
|
|
|
|
let char = profile.char
|
|
|
|
|
let tmp = char.getData('id,face,name,abbr,element,star')
|
2023-02-19 17:08:05 +00:00
|
|
|
|
let imgs = char.getImgs(profile.costume)
|
|
|
|
|
tmp.face = imgs.qFace || imgs.face
|
2023-02-13 19:47:22 +00:00
|
|
|
|
tmp.level = profile.level || 1
|
|
|
|
|
tmp.cons = profile.cons
|
|
|
|
|
tmp.isNew = 0
|
|
|
|
|
if (newChar[char.name]) {
|
|
|
|
|
tmp.isNew = 1
|
|
|
|
|
newCount++
|
|
|
|
|
}
|
|
|
|
|
if (rank) {
|
|
|
|
|
tmp.groupRank = await rank.getRank(profile, !!tmp.isNew)
|
|
|
|
|
}
|
|
|
|
|
chars.push(tmp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newCount > 0) {
|
|
|
|
|
hasNew = newCount <= 8
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chars = lodash.sortBy(chars, ['isNew', 'star', 'level', 'id'])
|
|
|
|
|
chars = chars.reverse()
|
2022-08-05 22:12:57 +00:00
|
|
|
|
|
2023-02-13 19:47:22 +00:00
|
|
|
|
player.save()
|
|
|
|
|
// 渲染图像
|
2024-02-04 01:27:34 +00:00
|
|
|
|
return e.reply([await Common.render('character/profile-list', {
|
2023-02-13 19:47:22 +00:00
|
|
|
|
save_id: uid,
|
|
|
|
|
uid,
|
|
|
|
|
chars,
|
|
|
|
|
servName,
|
|
|
|
|
hasNew,
|
|
|
|
|
msg,
|
|
|
|
|
groupRank,
|
2023-02-17 20:42:05 +00:00
|
|
|
|
updateTime: player.getUpdateTime(),
|
2023-02-13 19:47:22 +00:00
|
|
|
|
allowRank: rank && rank.allowRank,
|
2023-10-25 19:03:33 +00:00
|
|
|
|
rankCfg,
|
|
|
|
|
elem: player.isGs ? 'hydro' : 'sr'
|
2024-02-04 01:27:34 +00:00
|
|
|
|
}, { e, scale: 1.6, retType: "base64" }), new Button(e).profileList(uid, newChar)])
|
2023-02-17 20:42:05 +00:00
|
|
|
|
},
|
2023-10-25 19:03:33 +00:00
|
|
|
|
|
2023-02-17 20:42:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* 删除面板数据
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
*/
|
2024-02-04 01:27:34 +00:00
|
|
|
|
async del (e) {
|
|
|
|
|
let ret = /^#(删除全部面板|删除面板|删除面板数据)\s*(\d{9})?$/.exec(e.msg)
|
2023-02-17 20:42:05 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
|
if (!uid) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let targetUid = ret[2]
|
|
|
|
|
|
|
|
|
|
let user = e?.runtime?.user || {}
|
|
|
|
|
if (!user.hasCk && !e.isMaster) {
|
|
|
|
|
e.reply('为确保数据安全,目前仅允许绑定CK用户删除自己UID的面板数据,请联系Bot主人删除...')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!targetUid) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`你确认要删除面板数据吗? 请回复 #删除面板${uid} 以删除面板数据`, new Button(e).profileList(uid)])
|
2023-02-17 20:42:05 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let ckUids = (user?.ckUids || []).join(',').split(',')
|
|
|
|
|
if (!ckUids.includes(targetUid) && !e.isMaster) {
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`仅允许删除自己的UID数据[${ckUids.join(',')}]`, new Button(e).profileList(uid)])
|
2023-02-17 20:42:05 +00:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Player.delByUid(targetUid)
|
2024-02-04 01:27:34 +00:00
|
|
|
|
e.reply([`UID${targetUid}的本地数据已删除,排名数据已清除...`, new Button(e).profileList(uid)])
|
2023-02-17 20:42:05 +00:00
|
|
|
|
return true
|
2023-09-21 20:03:01 +00:00
|
|
|
|
},
|
|
|
|
|
|
2024-02-04 01:27:34 +00:00
|
|
|
|
async reload (e) {
|
2023-09-21 20:03:01 +00:00
|
|
|
|
let uid = await getTargetUid(e)
|
|
|
|
|
if (!uid) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let player = Player.create(e)
|
|
|
|
|
player.reload()
|
|
|
|
|
return ProfileList.render(e)
|
2023-02-13 19:47:22 +00:00
|
|
|
|
}
|
2022-08-05 22:12:57 +00:00
|
|
|
|
}
|
2024-02-04 01:27:34 +00:00
|
|
|
|
export default ProfileList
|