From 13665f4d2d7f0570c210023eca3582159ba4dff6 Mon Sep 17 00:00:00 2001 From: "ZM.J" Date: Thu, 16 May 2024 16:34:44 +0800 Subject: [PATCH] FIx: Match character id with different regex rules --- apps/profile/ProfileRank.js | 2 +- models/ProfileRank.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/apps/profile/ProfileRank.js b/apps/profile/ProfileRank.js index a821a417..2e8a9447 100644 --- a/apps/profile/ProfileRank.js +++ b/apps/profile/ProfileRank.js @@ -76,7 +76,7 @@ export async function groupRank (e) { if (char) { uids = await ProfileRank.getGroupUidList(groupId, char ? char.id : '', mode) } else { - uids = await ProfileRank.getGroupMaxUidList(groupId, mode) + uids = await ProfileRank.getGroupMaxUidList(groupId, mode, game) } if (uids.length > 0) { return renderCharRankList({ e, uids, char, mode, groupId }) diff --git a/models/ProfileRank.js b/models/ProfileRank.js index 4744f7e6..9a11bf7c 100644 --- a/models/ProfileRank.js +++ b/models/ProfileRank.js @@ -19,6 +19,16 @@ export default class ProfileRank { return rank } + static async getCharacterFromKey(key, game = 'gs') { + if (game === 'gs') { + // 原神的角色id都是8位 + return /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) + } else { + // 星铁的角色id都是4位 + return /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{4})$/.exec(key) + } + } + /** * 获取群排行UID * @param groupId @@ -31,11 +41,11 @@ export default class ProfileRank { return uids ? uids[0] : false } - static async getGroupMaxUidList (groupId, type = 'mark') { + static async getGroupMaxUidList (groupId, type = 'mark', game = 'gs') { let keys = await redis.keys(`miao:rank:${groupId}:${type}:*`) let ret = [] for (let key of keys) { - let keyRet = /^miao:rank:[\w-]+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) + let keyRet = await ProfileRank.getCharacterFromKey(key, game) if (keyRet && keyRet[1]) { let charId = keyRet[1] let uid = await ProfileRank.getGroupMaxUid(groupId, charId, type) @@ -78,7 +88,7 @@ export default class ProfileRank { static async resetRank (groupId, charId = '', game = 'gs') { let keys = await redis.keys(`miao:rank:${groupId}:*`) for (let key of keys) { - let charRet = game === 'gs' ? /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) : /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{4})$/.exec(key) + let charRet = await ProfileRank.getCharacterFromKey(key, game) if (charRet) { if (charId === '' || charId * 1 === charRet[1] * 1) { await redis.del(key) @@ -171,14 +181,14 @@ export default class ProfileRank { await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify(data), { EX: 3600 * 24 * 365 }) } - static async delUidInfo (uid) { + static async delUidInfo (uid, game = 'gs') { let keys = await redis.keys('miao:rank:*') uid = uid + '' if (!/\d{9,10}/.test(uid)) { return false } for (let key of keys) { - let charRet = /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key) + let charRet = await ProfileRank.getCharacterFromKey(key, game) if (charRet) { await redis.zRem(key, uid) }