修正最强胡桃的指令误触

This commit is contained in:
Kokomi 2022-11-11 04:56:15 +08:00
parent b3b874d85c
commit 917ee732dd
3 changed files with 74 additions and 22 deletions

View File

@ -1,8 +1,8 @@
import { Character, ProfileRank, ProfileDmg } from '../../models/index.js'
import { renderProfile } from './ProfileDetail.js'
import { Data } from '../../components/index.js'
import { Data, Profile, Format, Common } from '../../components/index.js'
export async function groupMaxProfile (e) {
export async function groupRank (e) {
let groupId = e.group_id
if (!groupId) {
return false
@ -10,29 +10,41 @@ export async function groupMaxProfile (e) {
const cfg = await Data.importCfg('cfg')
const groupRank = cfg?.diyCfg?.groupRank || false
let msg = e.original_msg || e.msg
if (!/(最强|最高|最高分|最牛|第一)/.test(msg)) {
let type = ''
if (/(排名|排行|列表)/.test(msg)) {
type = 'list'
} else if (/(最强|最高|最高分|最牛|第一)/.test(msg)) {
type = 'detail'
}
if (!type) {
return false
}
let mode = /(分|圣遗物|评分|ACE)/.test(msg) ? 'mark' : 'dmg'
if (!groupRank) {
e.reply('群面板排名功能已禁用...')
return true
}
let name = msg.replace(/(#|最强|最高分|第一|最高|最牛|圣遗物|评分|群内|群|排名|排行|面板|面版|详情)/g, '')
let name = msg.replace(/(#|最强|最高分|第一|最高|最牛|圣遗物|评分|群内|群|排名|排行|面板|面版|详情|榜)/g, '')
let char = Character.get(name)
if (!char) {
return false
}
let uid = await ProfileRank.getGroupMaxUid(groupId, char.id, mode)
if (uid) {
e.uid = uid
return await renderProfile(e, char)
} else {
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name)) {
e.reply(`${char.name}暂不支持伤害计算..`)
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)
} else {
e.reply('暂无排名信息')
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name)) {
e.reply(`${char.name}暂不支持伤害计算..`)
} else {
e.reply('暂无排名信息')
}
}
} else if (type === 'list') {
return true
let uids = await ProfileRank.getGroupUidList(groupId, char.id, mode)
return renderCharRankList({ e, uids, char, mode })
}
}
@ -61,3 +73,26 @@ export async function resetRank (e) {
await ProfileRank.resetRank(groupId, charId)
e.reply(`本群${charName}排名已重置...`)
}
async function renderCharRankList ({ e, uids, char, mode }) {
let list = []
for (let ds of uids) {
let uid = ds.value
let profile = Profile.get(uid, char.id)
if (profile) {
list.push({
uid,
value: Format.comma(ds.score)
})
}
}
// 渲染图像
return await Common.render('character/rank-profile-list', {
save_id: char.id,
char: char.getData('id,face,name,abbr,element,star'),
list,
elem: char.elem,
bodyClass: `char-${char.name}`,
mode
}, { e, scale: 1.6 })
}

View File

@ -6,7 +6,7 @@ import { renderProfile } from './character/ProfileDetail.js'
import { profileStat } from './character/ProfileStat.js'
import { profileList } from './character/ProfileList.js'
import { enemyLv } from './character/ProfileUtils.js'
import { groupMaxProfile, resetRank } from './character/ProfileRank.js'
import { groupRank, resetRank } from './character/ProfileRank.js'
let app = App.init({
id: 'profile',
@ -17,8 +17,8 @@ app.reg('profile-detail', profileDetail, {
name: '角色面板'
})
app.reg('group-profile', groupMaxProfile, {
rule: /^#?(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/,
app.reg('group-profile', groupRank, {
rule: /^#(群|群内)?(排名|排行)?(最强|最高|最高分|最牛|第一)+.+/,
name: '群内最强'
})
@ -26,7 +26,12 @@ app.reg('reset-rank', resetRank, {
rule: /^#(重置|重设)(.*)(排名|排行)$/,
name: '重置排名'
})
/*
app.reg('rank-list', groupRank, {
rule: /^#(群|群内)?.+(排名|排行|列表)(列表|榜)?$/,
name: '面板排名榜'
})
*/
app.reg('artis-list', profileArtisList, {
rule: /^#圣遗物列表\s*(\d{9})?$/,
name: '面板圣遗物列表'

View File

@ -31,7 +31,7 @@ export default class ProfileRank {
let markRank = await redis.zRevRank(markKey, this.uid)
if (!lodash.isNumber(markRank) || force) {
let mark = profile.getArtisMark(false)
if (mark) {
if (mark && mark._mark) {
await redis.zAdd(markKey, { score: mark._mark, value: this.uid })
markRank = await redis.zRevRank(markKey, this.uid)
}
@ -46,7 +46,7 @@ export default class ProfileRank {
let dmgRank = await redis.zRevRank(dmgKey, this.uid)
if (!lodash.isNumber(dmgRank) || force) {
let dmg = await profile.calcDmg({ mode: 'single' })
if (dmg) {
if (dmg && dmg.avg) {
await redis.zAdd(dmgKey, { score: dmg.avg, value: this.uid })
dmgRank = await redis.zRevRank(dmgKey, this.uid)
}
@ -82,6 +82,18 @@ export default class ProfileRank {
return uids ? uids[0] : false
}
/**
* 获取排行榜
* @param groupId
* @param charId
* @param type
* @returns {Promise<ConvertArgumentType<ZMember, string>[]|boolean>}
*/
static async getGroupUidList (groupId, charId, type = 'mark') {
let uids = await redis.zRangeWithScores(`miao:rank:${groupId}:${type}:${charId}`, -10, -1)
return uids ? uids.reverse() : false
}
/**
* 重置群排行
* @param groupId