增加#重置排名#重置刻晴排名命令

This commit is contained in:
Kokomi 2022-11-10 03:48:13 +08:00
parent 159660108d
commit 030a7be7ed
8 changed files with 159 additions and 20 deletions

View File

@ -5,6 +5,7 @@
* 统计自本次更新后开始记录,历史数据不会回溯
* 可通过`#面板`、`#心海面板`、`#更新面板`等命令来触发排名数据更新
* 增加`#最强雷神`、`#最高分甘雨`命令,查看当前统计中最高练度/最高圣遗物评分的面板数据
* 增加`#重置排名`、`#重置刻晴排名`命令,来重置当前群的排名统计
# 2.0.1~2.0.6

View File

@ -9,8 +9,9 @@ export async function profileList (e) {
return true
}
let rank = false
if (e.group_id) {
rank = await ProfileRank.create({ group: e.group_id, uid, qq: e.user_id })
let groupId = e.group_id
if (groupId) {
rank = await ProfileRank.create({ groupId, uid, qq: e.user_id })
}
let servName = Profile.getServName(uid)
let hasNew = false
@ -25,6 +26,7 @@ export async function profileList (e) {
}
const cfg = await Data.importCfg('cfg')
const groupRank = cfg?.diyCfg?.groupRank || false
const rankCfg = await ProfileRank.getGroupCfg(groupId)
await Profile.forEach(uid, async function (profile) {
if (!profile.hasData) {
return true
@ -71,6 +73,7 @@ export async function profileList (e) {
servName,
hasNew,
msg,
groupRank
groupRank,
rankCfg
}, { e, scale: 1.6 })
}

View File

@ -1,24 +1,31 @@
import { Character, ProfileRank, ProfileDmg } from '../../models/index.js'
import { renderProfile } from './ProfileDetail.js'
import { Data } from '../../components/index.js'
export async function groupMaxProfile (e) {
let groupId = e.group_id
if (!groupId) {
return false
}
const cfg = await Data.importCfg('cfg')
const groupRank = cfg?.diyCfg?.groupRank || false
let msg = e.original_msg || e.msg
if (!/(最强|最高|最高分|最牛|第一)/.test(msg)) {
return false
}
let mode = /(分|圣遗物|评分|ACE)/.test(msg) ? 'mark' : 'dmg'
if (!groupRank) {
e.reply('群面板排名功能已禁用...')
return true
}
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 && uid[0]) {
e.uid = uid[0]
if (uid) {
e.uid = uid
return await renderProfile(e, char)
} else {
if (mode === 'dmg' && !ProfileDmg.dmgRulePath(char.name)) {
@ -28,3 +35,29 @@ export async function groupMaxProfile (e) {
}
}
}
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
}
await ProfileRank.resetRank(groupId, charId)
e.reply(`本群${charName}排名已重置...`)
}

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 } from './character/ProfileRank.js'
import { groupMaxProfile, resetRank } from './character/ProfileRank.js'
let app = App.init({
id: 'profile',
@ -22,6 +22,11 @@ app.reg('group-profile', groupMaxProfile, {
name: '群内最强'
})
app.reg('reset-rank', resetRank, {
rule: /^#(重置|重设)(.*)(排名|排行)$/,
name: '重置排名'
})
app.reg('artis-list', profileArtisList, {
rule: /^#圣遗物列表\s*(\d{9})?$/,
name: '面板圣遗物列表'

View File

@ -1,9 +1,9 @@
import { Format } from '../components/index.js'
import lodash from 'lodash'
import moment from 'moment'
export default class ProfileRank {
constructor (data) {
this.group = data.group || data.groupId
this.groupId = data.groupId || data.groupId
this.qq = data.qq
this.uid = data.uid + ''
}
@ -13,9 +13,15 @@ export default class ProfileRank {
}
key (profile, type) {
return `miao:rank:${this.group}:${type}:${profile.id}`
return `miao:rank:${this.groupId}:${type}:${profile.id}`
}
/**
* 获取排行信息
* @param profile
* @param force
* @returns {Promise<{}|boolean>}
*/
async getRank (profile, force = false) {
if (!profile.hasData) {
return false
@ -64,7 +70,54 @@ export default class ProfileRank {
return ret
}
/**
* 获取群排行UID
* @param groupId
* @param charId
* @param type
* @returns {Promise<string|boolean>}
*/
static async getGroupMaxUid (groupId, charId, type = 'mark') {
return await redis.zRange(`miao:rank:${groupId}:${type}:${charId}`, -1, -1)
let uids = await redis.zRange(`miao:rank:${groupId}:${type}:${charId}`, -1, -1)
return uids ? uids[0] : false
}
/**
* 重置群排行
* @param groupId
* @param charId
* @returns {Promise<void>}
*/
static async resetRank (groupId, charId = '') {
let keys = await redis.keys(`miao:rank:${groupId}:*`)
for (let key of keys) {
let charRet = /^miao:rank:\d+:(?:mark|dmg):(\d{8})$/.exec(key)
if (charRet) {
if (charId === '' || charId * 1 === charRet[1] * 1) {
await redis.del(key)
}
}
}
if (charId === '') {
await redis.del(`miao:rank:${groupId}:cfg`)
}
}
static async getGroupCfg (groupId) {
let ret = {
timestamp: (new Date()) * 1,
status: 0
}
try {
let cfg = await redis.get(`miao:rank:${groupId}:cfg`)
if (!cfg) {
await redis.set(`miao:rank:${groupId}:cfg`, JSON.stringify(ret), { EX: 3600 * 24 * 365 })
} else {
ret = JSON.parse(cfg)
}
} catch (e) {
}
ret.time = moment(new Date(ret.timestamp)).format('MM-DD HH:mm')
return ret
}
}

View File

@ -126,12 +126,28 @@ body,
background: url("./imgs/mark-icon.png");
background-size: auto 100%;
display: inline-block;
vertical-align: middle;
margin-right: 2px;
vertical-align: bottom;
margin: -1px 3px -1px 0;
}
.group-rank-icon.mark-icon {
background-position: 100% 0;
}
.cont-title {
padding: 8px 5px;
background: rgba(0, 0, 0, 0.4);
}
.cont-title span {
color: #fff;
width: 50%;
}
.cont-title .rank-time {
font-size: 12px;
color: #aaa;
display: inline-block;
transform: scale(0.85);
transform-origin: 0 50%;
white-space: nowrap;
}
.no-rank .group-rank,
.no-rank .group-rank-tip {
display: none;

View File

@ -15,6 +15,17 @@
<div class="label">{{msg+", "}}更新角色时请不要出场对应角色,以获取准确面板数据</div>
<div class="label">你可以使用<span>#{{demo}}面板</span><span>#{{demo}}伤害</span><span>#{{demo}}圣遗物</span>命令来查看面板信息了</div>
</div>
<div class="cont group-rank-tip">
<div class="cont-title">
<span>
<i class="group-rank-icon dmg-icon"></i>综合练度排名
<i class="group-rank-icon mark-icon"></i>圣遗物评分排名
</span>
<span class="rank-time">
范围:本群内 / 时间:{{rankCfg.time}}后 / 通过 #面板 命令查看过的角色面板数据
</span>
</div>
</div>
<div class="cont {{groupRank?'has-rank':'no-rank'}}">
<div class="char-list">
{{each chars char}}
@ -38,14 +49,11 @@
{{if hasNew}}
<span class="new-tip">本次更新角色</span>
{{else}}
<span class="group-rank-tip">群内排名:
<i class="group-rank-icon dmg-icon"></i>综合练度
<i class="group-rank-icon mark-icon"></i>圣遗物评分
</span>
<span></span>
{{/if}}
<span class="serv">当前更新服务:{{servName}}</span>
</div>
</div>
</div>
</div>
{{/block}}

View File

@ -151,14 +151,34 @@ body, .container {
background: url("./imgs/mark-icon.png");
background-size: auto 100%;
display: inline-block;
vertical-align: middle;
margin-right: 2px;
vertical-align: bottom;
margin: -1px 3px -1px 0;
&.mark-icon {
background-position: 100% 0;
}
}
.cont-title {
padding: 8px 5px;
background: rgba(0, 0, 0, .4);
span {
color: #fff;
width: 50%;
}
.rank-time {
font-size: 12px;
color: #aaa;
display: inline-block;
transform: scale(.85);
transform-origin: 0 50%;
white-space: nowrap;
}
}
.no-rank .group-rank,
.no-rank .group-rank-tip {
display: none;