From 030a7be7edde6f3c460d7aac4f5dd17e22f84c57 Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Thu, 10 Nov 2022 03:48:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`#=E9=87=8D=E7=BD=AE=E6=8E=92?= =?UTF-8?q?=E5=90=8D`=E3=80=81`#=E9=87=8D=E7=BD=AE=E5=88=BB=E6=99=B4?= =?UTF-8?q?=E6=8E=92=E5=90=8D`=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + apps/character/ProfileList.js | 9 ++-- apps/character/ProfileRank.js | 37 +++++++++++++++- apps/profile.js | 7 ++- models/ProfileRank.js | 61 +++++++++++++++++++++++++-- resources/character/profile-list.css | 20 ++++++++- resources/character/profile-list.html | 20 ++++++--- resources/character/profile-list.less | 24 ++++++++++- 8 files changed, 159 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 567028e8..534f76d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * 统计自本次更新后开始记录,历史数据不会回溯 * 可通过`#面板`、`#心海面板`、`#更新面板`等命令来触发排名数据更新 * 增加`#最强雷神`、`#最高分甘雨`命令,查看当前统计中最高练度/最高圣遗物评分的面板数据 +* 增加`#重置排名`、`#重置刻晴排名`命令,来重置当前群的排名统计 # 2.0.1~2.0.6 diff --git a/apps/character/ProfileList.js b/apps/character/ProfileList.js index 6ce09e0c..955302df 100644 --- a/apps/character/ProfileList.js +++ b/apps/character/ProfileList.js @@ -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 }) } diff --git a/apps/character/ProfileRank.js b/apps/character/ProfileRank.js index 564677b9..78cfd0b7 100644 --- a/apps/character/ProfileRank.js +++ b/apps/character/ProfileRank.js @@ -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}排名已重置...`) +} diff --git a/apps/profile.js b/apps/profile.js index fb82d3d7..86e9e4dd 100644 --- a/apps/profile.js +++ b/apps/profile.js @@ -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: '面板圣遗物列表' diff --git a/models/ProfileRank.js b/models/ProfileRank.js index b04d4491..220ff0dd 100644 --- a/models/ProfileRank.js +++ b/models/ProfileRank.js @@ -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} + */ 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} + */ + 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 } } diff --git a/resources/character/profile-list.css b/resources/character/profile-list.css index 5b5b495f..b8961b2a 100644 --- a/resources/character/profile-list.css +++ b/resources/character/profile-list.css @@ -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; diff --git a/resources/character/profile-list.html b/resources/character/profile-list.html index bbd17c07..c019271f 100644 --- a/resources/character/profile-list.html +++ b/resources/character/profile-list.html @@ -15,6 +15,17 @@
{{msg+", "}}更新角色时请不要出场对应角色,以获取准确面板数据
你可以使用#{{demo}}面板#{{demo}}伤害#{{demo}}圣遗物命令来查看面板信息了
+
+
+ + 综合练度排名 + 圣遗物评分排名 + + + 范围:本群内 / 时间:{{rankCfg.time}}后 / 通过 #面板 命令查看过的角色面板数据 + +
+
{{each chars char}} @@ -38,14 +49,11 @@ {{if hasNew}} 本次更新角色 {{else}} - 群内排名: - 综合练度 - 圣遗物评分 - + {{/if}} 当前更新服务:{{servName}} + +
- - {{/block}} \ No newline at end of file diff --git a/resources/character/profile-list.less b/resources/character/profile-list.less index b9afc812..c3128ad2 100644 --- a/resources/character/profile-list.less +++ b/resources/character/profile-list.less @@ -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;