mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-16 04:35:42 +00:00
优化重置排名的处理逻辑
This commit is contained in:
parent
d74098b6df
commit
b56223e8ea
@ -1,6 +1,6 @@
|
|||||||
import { Character, ProfileRank, ProfileDmg, Player } from '#miao.models'
|
|
||||||
import ProfileDetail from './ProfileDetail.js'
|
import ProfileDetail from './ProfileDetail.js'
|
||||||
import { Data, Common, Format } from '#miao'
|
import { Data, Common, Format } from '#miao'
|
||||||
|
import { Character, ProfileRank, ProfileDmg, Player } from '#miao.models'
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
|
|
||||||
export async function groupRank (e) {
|
export async function groupRank (e) {
|
||||||
@ -113,7 +113,7 @@ export async function resetRank (e) {
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
export async function refreshRank (e) {
|
export async function refreshRank (e) {
|
||||||
let groupId = e.group_id
|
let groupId = e.group_id || ''
|
||||||
if (!groupId) {
|
if (!groupId) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -124,10 +124,10 @@ export async function refreshRank (e) {
|
|||||||
e.reply('面板数据刷新中,等待时间可能较长,请耐心等待...')
|
e.reply('面板数据刷新中,等待时间可能较长,请耐心等待...')
|
||||||
let game = e.isSr ? 'sr' : 'gs'
|
let game = e.isSr ? 'sr' : 'gs'
|
||||||
await ProfileRank.resetRank(groupId)
|
await ProfileRank.resetRank(groupId)
|
||||||
let groupUids = await Common.getGroupUids(e, game)
|
let uidMap = await ProfileRank.getUserUidMap(e, game)
|
||||||
let count = 0
|
let count = 0
|
||||||
for (let qq in groupUids) {
|
for (let uid in uidMap) {
|
||||||
for (let { uid, type } of groupUids[qq]) {
|
let { qq, type } = uidMap[uid]
|
||||||
let player = new Player(uid, game)
|
let player = new Player(uid, game)
|
||||||
let profiles = player.getProfiles()
|
let profiles = player.getProfiles()
|
||||||
// 刷新rankLimit
|
// 刷新rankLimit
|
||||||
@ -144,7 +144,6 @@ export async function refreshRank (e) {
|
|||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
e.reply(`本群排名已刷新,共刷新${count}个UID数据...`)
|
e.reply(`本群排名已刷新,共刷新${count}个UID数据...`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import Cfg from './Cfg.js'
|
import Cfg from './Cfg.js'
|
||||||
import Render from './common/Render.js'
|
import Render from './common/Render.js'
|
||||||
import { Version } from './index.js'
|
|
||||||
import lodash from 'lodash'
|
|
||||||
|
|
||||||
const Common = {
|
const Common = {
|
||||||
render: Render.render,
|
render: Render.render,
|
||||||
@ -12,86 +10,8 @@ const Common = {
|
|||||||
|
|
||||||
async downFile () {
|
async downFile () {
|
||||||
console.log('down file')
|
console.log('down file')
|
||||||
},
|
}
|
||||||
|
|
||||||
async getNoteQQUids (e, game='gs') {
|
|
||||||
let ret = {}
|
|
||||||
if (Version.isV3) {
|
|
||||||
if (e.runtime) {
|
|
||||||
let noteCks = await e.runtime?.gsCfg?.getBingCk(game) || {}
|
|
||||||
lodash.forEach(noteCks.ck, (ck, _qq) => {
|
|
||||||
let qq = ck.qq || _qq
|
|
||||||
let uid = ck.uid
|
|
||||||
if (qq && uid) {
|
|
||||||
ret[qq] = ret[qq] || []
|
|
||||||
if (!ret[qq].includes(uid)) {
|
|
||||||
ret[qq].push(uid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lodash.forEach(global.NoteCookie || {}, (ck) => {
|
|
||||||
const { qq, uid } = ck
|
|
||||||
if (qq && uid) {
|
|
||||||
ret[qq] = ret[qq] || []
|
|
||||||
ret[qq].push(uid)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
},
|
|
||||||
|
|
||||||
async getBindUid (qq, runtime, game = 'gs') {
|
|
||||||
if (Version.isMiao && runtime.NoteUser) {
|
|
||||||
let user = await runtime.NoteUser.create(qq)
|
|
||||||
return user ? user.getUid(game) : false
|
|
||||||
}
|
|
||||||
if (Version.isV3) {
|
|
||||||
return await redis.get(`Yz:genshin:mys:qq-uid:${qq}`)
|
|
||||||
} else {
|
|
||||||
return await redis.get(`genshin:id-uid:${qq}`)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async getGroupUids (e, game = 'gs') {
|
|
||||||
// 获取ck用户列表
|
|
||||||
let noteUids = await Common.getNoteQQUids(e, game)
|
|
||||||
let ret = {}
|
|
||||||
let uidMap = {}
|
|
||||||
|
|
||||||
let groupMemMap = await e.group?.getMemberMap()
|
|
||||||
// 优先匹配ck uid
|
|
||||||
for (let [qq] of groupMemMap) {
|
|
||||||
if (noteUids[qq]) {
|
|
||||||
for (let uid of noteUids[qq]) {
|
|
||||||
ret[qq] = ret[qq] || []
|
|
||||||
if (!uidMap[uid]) {
|
|
||||||
ret[qq].push({
|
|
||||||
uid,
|
|
||||||
type: 'ck'
|
|
||||||
})
|
|
||||||
uidMap[uid] = qq
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 获取绑定uid
|
|
||||||
for (let [qq] of groupMemMap) {
|
|
||||||
if (ret[qq]) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
let uid = await Common.getBindUid(qq, e.runtime, game)
|
|
||||||
if (uid && !uidMap[uid]) {
|
|
||||||
ret[qq] = [{
|
|
||||||
uid,
|
|
||||||
type: 'bind'
|
|
||||||
}]
|
|
||||||
uidMap[uid] = qq
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Common
|
export default Common
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { Cfg, Common, Data } from '#miao'
|
import { Cfg, Common, Data, Version } from '#miao'
|
||||||
|
|
||||||
export default class ProfileRank {
|
export default class ProfileRank {
|
||||||
constructor (data) {
|
constructor (data) {
|
||||||
@ -69,7 +69,7 @@ export default class ProfileRank {
|
|||||||
* @param charId
|
* @param charId
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async resetRank (groupId, groupMemList, charId = '') {
|
static async resetRank (groupId, charId = '') {
|
||||||
let keys = await redis.keys(`miao:rank:${groupId}:*`)
|
let keys = await redis.keys(`miao:rank:${groupId}:*`)
|
||||||
for (let key of keys) {
|
for (let key of keys) {
|
||||||
let charRet = /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key)
|
let charRet = /^miao:rank:\d+:(?:mark|dmg|crit|valid):(\d{8})$/.exec(key)
|
||||||
@ -188,6 +188,77 @@ export default class ProfileRank {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getUserUidMap (e, game = 'gs') {
|
||||||
|
let rn = e.runtime
|
||||||
|
let groupMemMap = await e.group?.getMemberMap() || []
|
||||||
|
let users = {}
|
||||||
|
for (let [qq] of groupMemMap) {
|
||||||
|
users[qq] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
let uidMap = {}
|
||||||
|
let qqMap = {}
|
||||||
|
let add = (qq, uid, type) => {
|
||||||
|
if (!uidMap || type === 'ck') {
|
||||||
|
uidMap[uid] = { uid, qq, type: type === 'ck' ? 'ck' : 'bind' }
|
||||||
|
}
|
||||||
|
qqMap[qq] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
let keys = await redis.keys('miao:rank:uid-info:*')
|
||||||
|
for (let key of keys) {
|
||||||
|
let data = await Data.redisGet(key)
|
||||||
|
let { qq, uidType } = data
|
||||||
|
if (!users[qq]) continue
|
||||||
|
let uidRet = /miao:rank:uid-info:(\d{9})/.exec(key)
|
||||||
|
if (qq && uidType && uidRet?.[1]) {
|
||||||
|
add(qq, uidRet[1], uidType === 'ck' ? 'ck' : 'bind')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rn.NoteUser) {
|
||||||
|
// Miao-Yunzai
|
||||||
|
await rn.NoteUser.forEach(async (user) => {
|
||||||
|
if (!users[user.qq]) return true
|
||||||
|
let uids = user.getUidList(game)
|
||||||
|
lodash.forEach(uids, (ds) => {
|
||||||
|
let { uid, type } = ds
|
||||||
|
add(user.qq, uid, type)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else if (Version.isV3) {
|
||||||
|
if (rn?.gsCfg?.getBingCk) {
|
||||||
|
// Yunzai-V3
|
||||||
|
let noteCks = await rn.gsCfg.getBingCk(game) || {}
|
||||||
|
lodash.forEach(noteCks.ck, (ck, _qq) => {
|
||||||
|
let qq = ck.qq || _qq
|
||||||
|
let uid = ck.uid
|
||||||
|
if (!users[qq]) return true
|
||||||
|
add(qq, uid, 'ck')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// V2
|
||||||
|
lodash.forEach(global.NoteCookie || {}, (ck) => {
|
||||||
|
const { qq, uid } = ck
|
||||||
|
if (!users[qq]) return true
|
||||||
|
if (qq && uid) {
|
||||||
|
add(qq, uid, 'ck')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let qq in users) {
|
||||||
|
if (qqMap[qq]) continue
|
||||||
|
let uid = await redis.get(Version.isV3 ? `Yz:genshin:mys:qq-uid:${qq}` : `genshin:id-uid:${qq}`)
|
||||||
|
if (uid) {
|
||||||
|
add(qq, uid, 'bind')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return uidMap
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1: '无限制',
|
* 1: '无限制',
|
||||||
* 2: '绑定有CK的用户',
|
* 2: '绑定有CK的用户',
|
||||||
@ -347,4 +418,6 @@ export default class ProfileRank {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user