增加命令 #最强排行#最高分排行 查看群排行

This commit is contained in:
Kokomi 2022-11-18 02:25:32 +08:00
parent 6720eba0ba
commit ead88813f0
4 changed files with 39 additions and 8 deletions

View File

@ -2,6 +2,7 @@
* 角色面板彩蛋图(满命/三皇冠/ACE 任一触发)支持自定义
* 自定义图像可放置在 **resources/profile/super-character/** 目录下
* 增加命令 `#最强排行`、`#最高分排行` 查看群排行
# 2.0.1~2.0.9

View File

@ -21,7 +21,7 @@ export async function groupRank (e) {
let mode = /(分|圣遗物|评分|ACE)/.test(msg) ? 'mark' : 'dmg'
let name = msg.replace(/(#|最强|最高分|第一|最高|最牛|圣遗物|评分|群内|群|排名|排行|面板|面版|详情|榜)/g, '')
let char = Character.get(name)
if (!char) {
if (!char && type !== 'list') {
return false
}
if (!groupRank) {
@ -41,10 +41,15 @@ export async function groupRank (e) {
}
}
} else if (type === 'list') {
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name)) {
if (mode === 'dmg' && char && !ProfileDmg.dmgRulePath(char.name)) {
e.reply(`暂无排名:${char.name}暂不支持伤害计算,无法进行排名..`)
} else {
let uids = await ProfileRank.getGroupUidList(groupId, char.id, mode)
let uids = []
if (char) {
uids = await ProfileRank.getGroupUidList(groupId, char ? char.id : '', mode)
} else {
uids = await ProfileRank.getGroupMaxUidList(groupId, mode)
}
if (uids.length > 0) {
return renderCharRankList({ e, uids, char, mode, groupId })
} else {
@ -121,10 +126,10 @@ export async function refreshRank (e) {
async function renderCharRankList ({ e, uids, char, mode, groupId }) {
let list = []
for (let ds of uids) {
let uid = ds.value
let profile = Profile.get(uid, char.id)
let uid = ds.uid || ds.value
let profile = Profile.get(uid, ds.charId || char.id)
if (profile) {
let profileRank = await ProfileRank.create({ groupId, uid })
let data = await profileRank.getRank(profile, true)
@ -132,6 +137,7 @@ async function renderCharRankList ({ e, uids, char, mode, groupId }) {
let avatar = new Avatar(profile, uid)
let tmp = {
uid,
isMax: true,
...avatar.getData('id,star,name,sName,level,fetter,cons,weapon,elem,talent,artisSet,imgs'),
artisMark: Data.getData(mark, 'mark,markClass')
}
@ -161,7 +167,12 @@ async function renderCharRankList ({ e, uids, char, mode, groupId }) {
list.push(tmp)
}
}
let title = `#${char.name}${mode === 'mark' ? '圣遗物' : ''}排行`
let title
if (char) {
title = `#${char.name}${mode === 'mark' ? '圣遗物' : ''}排行`
} else {
title = `#${mode === 'mark' ? '最高分' : '最强'}排行`
}
const rankCfg = await ProfileRank.getGroupCfg(groupId)
// 渲染图像
return await Common.render('character/rank-profile-list', {

View File

@ -118,6 +118,25 @@ export default class ProfileRank {
return uids ? uids[0] : false
}
static async getGroupMaxUidList (groupId, type = 'mark') {
let keys = await redis.keys(`miao:rank:${groupId}:${type}:*`)
let ret = []
for (let key of keys) {
let keyRet = /^miao:rank:\d+:(?:mark|dmg):(\d{8})$/.exec(key)
if (keyRet && keyRet[1]) {
let charId = keyRet[1]
let uid = await ProfileRank.getGroupMaxUid(groupId, charId, type)
if (uid) {
ret.push({
uid,
charId
})
}
}
}
return ret
}
/**
* 获取排行榜
* @param groupId

View File

@ -41,7 +41,7 @@
{{each list ds idx}}
<div class="cont char-list-item">
<div class="char-idx">
<span class="idx-{{idx+1}} mode-{{mode}}">{{idx+1}}</span>
<span class="idx-{{ds.isMax ? 1 : idx+1}} mode-{{mode}}">{{idx+1}}</span>
</div>
<div class="item-icon char-icon star{{ds.star}}">
{{if ds.qqFace}}