2022-11-11 21:57:13 +00:00
|
|
|
|
import { Character, ProfileRank, ProfileDmg, Avatar } from '../../models/index.js'
|
2022-11-08 22:04:08 +00:00
|
|
|
|
import { renderProfile } from './ProfileDetail.js'
|
2022-11-11 21:57:13 +00:00
|
|
|
|
import { Data, Profile, Common, Format } from '../../components/index.js'
|
2022-11-17 18:55:06 +00:00
|
|
|
|
import lodash from 'lodash'
|
2022-11-08 22:04:08 +00:00
|
|
|
|
|
2022-11-10 20:56:15 +00:00
|
|
|
|
export async function groupRank (e) {
|
2022-11-08 22:04:08 +00:00
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!groupId) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
const groupRank = Common.cfg('groupRank')
|
2022-11-08 22:04:08 +00:00
|
|
|
|
let msg = e.original_msg || e.msg
|
2022-11-10 20:56:15 +00:00
|
|
|
|
let type = ''
|
|
|
|
|
if (/(排名|排行|列表)/.test(msg)) {
|
|
|
|
|
type = 'list'
|
|
|
|
|
} else if (/(最强|最高|最高分|最牛|第一)/.test(msg)) {
|
|
|
|
|
type = 'detail'
|
|
|
|
|
}
|
|
|
|
|
if (!type) {
|
2022-11-08 22:04:08 +00:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
let mode = /(分|圣遗物|评分|ACE)/.test(msg) ? 'mark' : 'dmg'
|
2022-11-10 20:56:15 +00:00
|
|
|
|
let name = msg.replace(/(#|最强|最高分|第一|最高|最牛|圣遗物|评分|群内|群|排名|排行|面板|面版|详情|榜)/g, '')
|
2022-11-08 22:04:08 +00:00
|
|
|
|
let char = Character.get(name)
|
2022-11-22 20:25:36 +00:00
|
|
|
|
if (!char) {
|
|
|
|
|
// 名字不存在或不为列表模式,则返回false
|
|
|
|
|
if (name || type !== 'list') {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-11-08 22:04:08 +00:00
|
|
|
|
}
|
2022-11-10 20:56:15 +00:00
|
|
|
|
if (!groupRank) {
|
|
|
|
|
e.reply('群面板排名功能已禁用...')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (type === 'detail') {
|
|
|
|
|
let uid = await ProfileRank.getGroupMaxUid(groupId, char.id, mode)
|
|
|
|
|
if (uid) {
|
|
|
|
|
e.uid = uid
|
|
|
|
|
return await renderProfile(e, char)
|
2022-11-08 22:32:20 +00:00
|
|
|
|
} else {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name)) {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
e.reply(`暂无排名:${char.name}暂不支持伤害计算,无法进行排名..`)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
} else {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
e.reply('暂无排名:请通过【#面板】查看角色面板以更新排名信息...')
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|
2022-11-08 22:32:20 +00:00
|
|
|
|
}
|
2022-11-10 20:56:15 +00:00
|
|
|
|
} else if (type === 'list') {
|
2022-11-17 18:25:32 +00:00
|
|
|
|
if (mode === 'dmg' && char && !ProfileDmg.dmgRulePath(char.name)) {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
e.reply(`暂无排名:${char.name}暂不支持伤害计算,无法进行排名..`)
|
|
|
|
|
} else {
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let uids = []
|
|
|
|
|
if (char) {
|
|
|
|
|
uids = await ProfileRank.getGroupUidList(groupId, char ? char.id : '', mode)
|
|
|
|
|
} else {
|
|
|
|
|
uids = await ProfileRank.getGroupMaxUidList(groupId, mode)
|
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
if (uids.length > 0) {
|
|
|
|
|
return renderCharRankList({ e, uids, char, mode, groupId })
|
|
|
|
|
} else {
|
|
|
|
|
e.reply('暂无排名:请通过【#面板】查看角色面板以更新排名信息...')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
2022-11-08 22:04:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-09 19:48:13 +00:00
|
|
|
|
|
|
|
|
|
export async function resetRank (e) {
|
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!groupId) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (!e.isMaster) {
|
|
|
|
|
e.reply('只有管理员可重置排名')
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
let msg = e.original_msg || e.msg
|
|
|
|
|
let name = msg.replace(/(#|重置|重设|排名|排行|群|群内|面板|详情|面版)/g, '').trim()
|
|
|
|
|
let charId = ''
|
|
|
|
|
let charName = '全部角色'
|
|
|
|
|
if (name) {
|
|
|
|
|
let char = Character.get(name)
|
|
|
|
|
if (!char) {
|
|
|
|
|
e.reply(`重置排名失败,角色:${name}不存在`)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
charId = char.id
|
|
|
|
|
charName = char.name
|
|
|
|
|
}
|
2022-11-15 20:07:21 +00:00
|
|
|
|
await ProfileRank.resetRank(groupId, charId)
|
2022-11-09 19:48:13 +00:00
|
|
|
|
e.reply(`本群${charName}排名已重置...`)
|
|
|
|
|
}
|
2022-11-10 20:56:15 +00:00
|
|
|
|
|
2022-11-15 20:58:19 +00:00
|
|
|
|
/**
|
|
|
|
|
* 刷新群排名信息
|
|
|
|
|
* @param e
|
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
|
*/
|
2022-11-15 20:07:21 +00:00
|
|
|
|
export async function refreshRank (e) {
|
|
|
|
|
let groupId = e.group_id
|
|
|
|
|
if (!groupId) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (!e.isMaster) {
|
|
|
|
|
e.reply('只有管理员可刷新排名...')
|
|
|
|
|
return true
|
|
|
|
|
}
|
2022-11-16 14:11:04 +00:00
|
|
|
|
e.reply('面板数据刷新中,等待时间可能较长,请耐心等待...')
|
2022-11-15 20:07:21 +00:00
|
|
|
|
let groupUids = await Common.getGroupUids(e)
|
|
|
|
|
let count = 0
|
|
|
|
|
for (let qq in groupUids) {
|
|
|
|
|
for (let { uid, type } of groupUids[qq]) {
|
|
|
|
|
let profiles = Profile.getAll(uid)
|
|
|
|
|
// 刷新rankLimit
|
2022-11-15 20:58:19 +00:00
|
|
|
|
await ProfileRank.setUidInfo({ uid, profiles, qq, uidType: type })
|
2022-11-15 20:07:21 +00:00
|
|
|
|
let rank = await ProfileRank.create({ groupId, uid, qq })
|
|
|
|
|
for (let id in profiles) {
|
|
|
|
|
let profile = profiles[id]
|
|
|
|
|
if (!profile.hasData) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
await rank.getRank(profile, true)
|
|
|
|
|
}
|
2022-11-15 20:25:07 +00:00
|
|
|
|
if (rank.allowRank) {
|
|
|
|
|
count++
|
|
|
|
|
}
|
2022-11-15 20:07:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e.reply(`本群排名已刷新,共刷新${count}个UID数据...`)
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-12 13:29:53 +00:00
|
|
|
|
async function renderCharRankList ({ e, uids, char, mode, groupId }) {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
let list = []
|
|
|
|
|
for (let ds of uids) {
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let uid = ds.uid || ds.value
|
|
|
|
|
let profile = Profile.get(uid, ds.charId || char.id)
|
|
|
|
|
|
2022-11-10 20:56:15 +00:00
|
|
|
|
if (profile) {
|
2022-11-12 21:35:46 +00:00
|
|
|
|
let profileRank = await ProfileRank.create({ groupId, uid })
|
|
|
|
|
let data = await profileRank.getRank(profile, true)
|
|
|
|
|
let mark = data?.mark?.data
|
2022-11-11 21:57:13 +00:00
|
|
|
|
let avatar = new Avatar(profile, uid)
|
|
|
|
|
let tmp = {
|
2022-11-10 20:56:15 +00:00
|
|
|
|
uid,
|
2022-11-17 18:55:06 +00:00
|
|
|
|
isMax: !char,
|
2022-11-11 21:57:13 +00:00
|
|
|
|
...avatar.getData('id,star,name,sName,level,fetter,cons,weapon,elem,talent,artisSet,imgs'),
|
|
|
|
|
artisMark: Data.getData(mark, 'mark,markClass')
|
|
|
|
|
}
|
2022-11-12 21:35:46 +00:00
|
|
|
|
let dmg = data?.dmg?.data
|
2022-11-11 21:57:13 +00:00
|
|
|
|
if (dmg && dmg.avg) {
|
2022-11-12 13:29:53 +00:00
|
|
|
|
let title = dmg.title
|
|
|
|
|
// 稍微缩短下title
|
|
|
|
|
if (title.length > 10) {
|
|
|
|
|
title = title.replace(/[ ·]*/g, '')
|
|
|
|
|
}
|
|
|
|
|
title = title.length > 10 ? title.replace(/伤害$/, '') : title
|
2022-11-11 21:57:13 +00:00
|
|
|
|
tmp.dmg = {
|
2022-11-12 13:29:53 +00:00
|
|
|
|
title: title,
|
2022-11-11 21:57:13 +00:00
|
|
|
|
avg: Format.comma(dmg.avg, 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-15 20:58:19 +00:00
|
|
|
|
if (uid) {
|
|
|
|
|
let userInfo = await ProfileRank.getUidInfo(uid)
|
|
|
|
|
if (userInfo && userInfo.qq) {
|
|
|
|
|
let member = e.group?.pickMember(userInfo.qq * 1)
|
|
|
|
|
let img = member?.getAvatarUrl(140)
|
|
|
|
|
if (img) {
|
|
|
|
|
tmp.qqFace = img
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-23 02:22:45 +00:00
|
|
|
|
tmp._mark = mark?._mark || 0
|
2022-11-17 19:13:59 +00:00
|
|
|
|
tmp._dmg = dmg?.avg || 0
|
2022-11-17 19:40:32 +00:00
|
|
|
|
tmp._star = 5 - tmp.star
|
2022-11-11 21:57:13 +00:00
|
|
|
|
list.push(tmp)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-17 18:25:32 +00:00
|
|
|
|
let title
|
|
|
|
|
if (char) {
|
|
|
|
|
title = `#${char.name}${mode === 'mark' ? '圣遗物' : ''}排行`
|
2022-11-17 18:55:06 +00:00
|
|
|
|
list = lodash.sortBy(list, mode === 'mark' ? '_mark' : '_dmg').reverse()
|
2022-11-17 18:25:32 +00:00
|
|
|
|
} else {
|
|
|
|
|
title = `#${mode === 'mark' ? '最高分' : '最强'}排行`
|
2022-11-17 19:40:32 +00:00
|
|
|
|
list = lodash.sortBy(list, ['uid', '_star', 'id'])
|
2022-11-17 18:25:32 +00:00
|
|
|
|
}
|
2022-11-17 18:55:06 +00:00
|
|
|
|
|
2022-11-12 13:29:53 +00:00
|
|
|
|
const rankCfg = await ProfileRank.getGroupCfg(groupId)
|
2022-11-10 20:56:15 +00:00
|
|
|
|
// 渲染图像
|
|
|
|
|
return await Common.render('character/rank-profile-list', {
|
|
|
|
|
save_id: char.id,
|
|
|
|
|
list,
|
2022-11-11 21:57:13 +00:00
|
|
|
|
title,
|
2022-11-10 20:56:15 +00:00
|
|
|
|
elem: char.elem,
|
|
|
|
|
bodyClass: `char-${char.name}`,
|
2022-11-12 13:29:53 +00:00
|
|
|
|
rankCfg,
|
2022-11-10 20:56:15 +00:00
|
|
|
|
mode
|
2022-11-11 21:57:13 +00:00
|
|
|
|
}, { e, scale: 1.4 })
|
2022-11-10 20:56:15 +00:00
|
|
|
|
}
|