面板排名支持限制是否绑定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) {
return true
}
let isSelfUid = false
if (e.runtime) {
let uids = e.runtime?.user?.ckUids || []
isSelfUid = uids.join(',').split(',').includes(uid + '')
}
let rank = false
let servName = Profile.getServName(uid)
let hasNew = false
let newCount = 0
@ -25,7 +29,7 @@ export async function profileList (e) {
// 获取面板数据
let profiles = Profile.getAll(uid)
// 检测标志位
await ProfileRank.setRankLimit(uid, profiles)
await ProfileRank.setRankLimit(uid, profiles, isSelfUid)
let groupId = e.group_id
if (groupId) {

View File

@ -36,7 +36,11 @@ let Profile = {
let userData = {}
const userFile = `${userPath}/${uid}.json`
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(',')))
userData.chars = userData.chars || {}
@ -93,7 +97,11 @@ let Profile = {
const userFile = `${userPath}/${uid}.json`
let userData = {}
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) {
let ret = {}

View File

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

View File

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

View File

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

View File

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

View File

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