面板排名支持限制是否绑定CK

This commit is contained in:
Kokomi 2022-11-14 04:43:59 +08:00
parent 34a0e1f0f3
commit 7e519fdfe3
7 changed files with 58 additions and 20 deletions

View File

@ -8,8 +8,12 @@ export async function profileList (e) {
if (!uid) { if (!uid) {
return true return true
} }
let isSelfUid = false
if (e.runtime) {
let uids = e.runtime?.user?.ckUids || []
isSelfUid = uids.join(',').split(',').includes(uid + '')
}
let rank = false let rank = false
let servName = Profile.getServName(uid) let servName = Profile.getServName(uid)
let hasNew = false let hasNew = false
let newCount = 0 let newCount = 0
@ -25,7 +29,7 @@ export async function profileList (e) {
// 获取面板数据 // 获取面板数据
let profiles = Profile.getAll(uid) let profiles = Profile.getAll(uid)
// 检测标志位 // 检测标志位
await ProfileRank.setRankLimit(uid, profiles) await ProfileRank.setRankLimit(uid, profiles, isSelfUid)
let groupId = e.group_id let groupId = e.group_id
if (groupId) { if (groupId) {

View File

@ -36,7 +36,11 @@ let Profile = {
let userData = {} let userData = {}
const userFile = `${userPath}/${uid}.json` const userFile = `${userPath}/${uid}.json`
if (fs.existsSync(userFile)) { if (fs.existsSync(userFile)) {
userData = JSON.parse(fs.readFileSync(userFile, 'utf8')) || {} try {
userData = JSON.parse(fs.readFileSync(userFile, 'utf8')) || {}
} catch (e) {
userData = {}
}
} }
lodash.assignIn(userData, lodash.pick(data, 'uid,name,lv,avatar'.split(','))) lodash.assignIn(userData, lodash.pick(data, 'uid,name,lv,avatar'.split(',')))
userData.chars = userData.chars || {} userData.chars = userData.chars || {}
@ -93,7 +97,11 @@ let Profile = {
const userFile = `${userPath}/${uid}.json` const userFile = `${userPath}/${uid}.json`
let userData = {} let userData = {}
if (fs.existsSync(userFile)) { if (fs.existsSync(userFile)) {
userData = JSON.parse(fs.readFileSync(userFile, 'utf8')) || {} try {
userData = JSON.parse(fs.readFileSync(userFile, 'utf8')) || {}
} catch (e) {
userData = {}
}
} }
if (userData && userData.chars) { if (userData && userData.chars) {
let ret = {} let ret = {}

View File

@ -27,7 +27,7 @@ export const cfgSchema = {
key: '限制', key: '限制',
def: 1, def: 1,
type: 'num', type: 'num',
desc: '参与排名的限制条件1:无限制 2:有16个角色 3:有御三家(安柏&凯亚&丽莎) 4:有16个角色+御三家。若改变设置请根据情况决定是否需要【#重置排名】' desc: '参与排名的限制条件1:无限制 2:有CK 3:有16个角色或有CK 4:有御三家(安柏&凯亚&丽莎)或有CK 5:有16个角色+御三家或有CK。 若改变设置请根据情况决定是否需要【#重置排名】'
}, },
uploadAbyssData: { uploadAbyssData: {
title: '上传深渊', title: '上传深渊',

View File

@ -151,14 +151,14 @@ export default class ProfileRank {
static async getGroupCfg (groupId) { static async getGroupCfg (groupId) {
const rankLimitTxt = { const rankLimitTxt = {
1: '无限制', 1: '无限制',
2: '面板列表中至少有16个角色的数据', 2: '绑定有CK的用户',
3: '面板列表中有 安柏&凯亚&丽莎 的数据', 3: '绑定CK或列表有16个角色数据',
4: '面板列表至少有16个角色数据且包含安柏&凯亚&丽莎' 4: '绑定CK或列表有安柏&凯亚&丽莎的数据',
5: '绑定CK或列表有16个角色数据且包含安柏&凯亚&丽莎'
} }
let rankLimit = Common.cfg('groupRankLimit') * 1 || 1 let rankLimit = Common.cfg('groupRankLimit') * 1 || 1
let ret = { let ret = {
timestamp: (new Date()) * 1, timestamp: (new Date()) * 1,
limitTxt: rankLimitTxt[rankLimit],
status: 0 status: 0
} }
try { try {
@ -170,11 +170,12 @@ export default class ProfileRank {
} }
} catch (e) { } catch (e) {
} }
ret.limitTxt = rankLimitTxt[rankLimit]
ret.time = moment(new Date(ret.timestamp)).format('MM-DD HH:mm') ret.time = moment(new Date(ret.timestamp)).format('MM-DD HH:mm')
return ret return ret
} }
static async setRankLimit (uid, profiles) { static async setRankLimit (uid, profiles, isSelfUid = false) {
if (!uid) { if (!uid) {
return false return false
} }
@ -190,12 +191,31 @@ export default class ProfileRank {
} }
totalCount++ totalCount++
} }
let data = {}
try {
data = await redis.get(`miao:rank:uid-info:${uid}`)
if (data) {
data = JSON.parse(data)
}
} catch (e) {
data = {}
}
await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify({ await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify({
totalCount, totalCount,
basicCount basicCount,
isSelfUid: !!(isSelfUid || data.isSelfUid)
}), { EX: 3600 * 24 * 365 }) }), { EX: 3600 * 24 * 365 })
} }
/**
* 1: '无限制',
* 2: '绑定有CK的用户',
* 3: '面板列表有16个角色数据或绑定CK',
* 4: '面板列表有安柏&凯亚&丽莎的数据或绑定CK',
* 5: '面板列表有16个角色数据且包含安柏&凯亚&丽莎或绑定CK'
* @param uid
* @returns {Promise<boolean>}
*/
static async checkRankLimit (uid) { static async checkRankLimit (uid) {
if (!uid) { if (!uid) {
return false return false
@ -207,10 +227,16 @@ export default class ProfileRank {
} }
let data = await redis.get(`miao:rank:uid-info:${uid}`) let data = await redis.get(`miao:rank:uid-info:${uid}`)
data = JSON.parse(data) data = JSON.parse(data)
if ((data.totalCount || 0) < 16 && [2, 4].includes(rankLimit)) { if (data.isSelfUid) {
return true
}
if (rankLimit === 2) {
return false return false
} }
if ((data.basicCount || 0) < 3 && [3, 4].includes(rankLimit)) { if ((data.totalCount || 0) < 16 && [3, 5].includes(rankLimit)) {
return false
}
if ((data.basicCount || 0) < 3 && [4, 5].includes(rankLimit)) {
return false return false
} }
return true return true

View File

@ -1,11 +1,11 @@
body { body {
transform: scale(1); transform: scale(1);
width: 520px; width: 700px;
} }
.container { .container {
background: url("./imgs/bg.png") #000144 left top no-repeat; background: url("./imgs/bg.png") #000144 left top no-repeat;
background-size: 520px auto; background-size: 700px auto;
width: 520px; width: 700px;
} }
.head-box { .head-box {
margin: 0 0 80px 0; margin: 0 0 80px 0;

View File

@ -1,12 +1,12 @@
body { body {
transform: scale(1); transform: scale(1);
width: 520px; width: 700px;
} }
.container { .container {
background: url("./imgs/bg.png") #000144 left top no-repeat; background: url("./imgs/bg.png") #000144 left top no-repeat;
background-size: 520px auto; background-size: 700px auto;
width:520px; width:700px;
} }
.head-box { .head-box {

View File

@ -17,7 +17,7 @@
</div> </div>
<div class="cont group-rank-tip {{groupRank?'has-rank':'no-rank'}}"> <div class="cont group-rank-tip {{groupRank?'has-rank':'no-rank'}}">
<div class="cont-title"> <div class="cont-title">
{{if !allowRank || true}} {{if !allowRank}}
<span> <i class="group-rank-icon dmg-icon"></i>本面板暂未参与排名,参与要求:{{rankCfg.limitTxt}} </span> <span> <i class="group-rank-icon dmg-icon"></i>本面板暂未参与排名,参与要求:{{rankCfg.limitTxt}} </span>
{{else}} {{else}}
<span> <span>