增加命令#刷新排名,自动获取群成员的面板信息进行重排

This commit is contained in:
Kokomi 2022-11-16 04:07:21 +08:00
parent 725a1c25d4
commit 341fe15972
6 changed files with 155 additions and 54 deletions

View File

@ -29,7 +29,7 @@ export async function profileList (e) {
// 获取面板数据 // 获取面板数据
let profiles = Profile.getAll(uid) let profiles = Profile.getAll(uid)
// 检测标志位 // 检测标志位
await ProfileRank.setRankLimit(uid, profiles, isSelfUid) await ProfileRank.setRankUidInfo({ uid, profiles, qq: e.user_id, uidType: isSelfUid ? 'ck' : 'bind' })
let groupId = e.group_id let groupId = e.group_id
if (groupId) { if (groupId) {

View File

@ -68,12 +68,6 @@ export async function resetRank (e) {
let name = msg.replace(/(#|重置|重设|排名|排行|群|群内|面板|详情|面版)/g, '').trim() let name = msg.replace(/(#|重置|重设|排名|排行|群|群内|面板|详情|面版)/g, '').trim()
let charId = '' let charId = ''
let charName = '全部角色' let charName = '全部角色'
let groupMemList = []
let groupMemMap = await e.group.getMemberMap()
groupMemMap.forEach((v, k) => {
groupMemList.push(k)
});
if (name) { if (name) {
let char = Character.get(name) let char = Character.get(name)
if (!char) { if (!char) {
@ -83,10 +77,55 @@ export async function resetRank (e) {
charId = char.id charId = char.id
charName = char.name charName = char.name
} }
await ProfileRank.resetRank(groupId, groupMemList, charId) await ProfileRank.resetRank(groupId, charId)
e.reply(`本群${charName}排名已重置...`) e.reply(`本群${charName}排名已重置...`)
} }
const getUid = async function (qq) {
let uidReg = /[1-9][0-9]{8}/
let nCookie = global.NoteCookie || false
if (nCookie && nCookie[qq]) {
let nc = nCookie[qq]
if (nc.uid && uidReg.test(nc.uid)) {
return nc.uid
}
}
let uid = await redis.get(`Yz:genshin:mys:qq-uid:${qq}`)
if (uid && uidReg.test(uid)) {
return uid
}
}
export async function refreshRank (e) {
let groupId = e.group_id
if (!groupId) {
return true
}
if (!e.isMaster) {
e.reply('只有管理员可刷新排名...')
return true
}
let groupUids = await Common.getGroupUids(e)
let count = 0
for (let qq in groupUids) {
for (let { uid, type } of groupUids[qq]) {
let profiles = Profile.getAll(uid)
// 刷新rankLimit
await ProfileRank.setRankUidInfo({ uid, profiles, qq, uidType: type })
let rank = await ProfileRank.create({ groupId, uid, qq })
for (let id in profiles) {
let profile = profiles[id]
if (!profile.hasData) {
continue
}
await rank.getRank(profile, true)
}
count++
}
}
e.reply(`本群排名已刷新,共刷新${count}个UID数据...`)
}
async function renderCharRankList ({ e, uids, char, mode, groupId }) { async function renderCharRankList ({ e, uids, char, mode, groupId }) {
let list = [] let list = []

View File

@ -6,7 +6,7 @@ import { renderProfile } from './character/ProfileDetail.js'
import { profileStat } from './character/ProfileStat.js' import { profileStat } from './character/ProfileStat.js'
import { profileList } from './character/ProfileList.js' import { profileList } from './character/ProfileList.js'
import { enemyLv } from './character/ProfileUtils.js' import { enemyLv } from './character/ProfileUtils.js'
import { groupRank, resetRank } from './character/ProfileRank.js' import { groupRank, resetRank, refreshRank } from './character/ProfileRank.js'
let app = App.init({ let app = App.init({
id: 'profile', id: 'profile',
@ -27,6 +27,11 @@ app.reg('reset-rank', resetRank, {
name: '重置排名' name: '重置排名'
}) })
app.reg('refresh-rank', refreshRank, {
rule: /^#(刷新)(全部)?(排名|排行)$/,
name: '重置排名'
})
app.reg('rank-list', groupRank, { app.reg('rank-list', groupRank, {
rule: /^#(群|群内)?.+(排名|排行|列表)(列表|榜)?$/, rule: /^#(群|群内)?.+(排名|排行|列表)(列表|榜)?$/,
name: '面板排名榜' name: '面板排名榜'

View File

@ -1,12 +1,90 @@
import Cfg from './Cfg.js' import Cfg from './Cfg.js'
import render from './common-lib/render.js' import render from './common-lib/render.js'
import { Version } from './index.js'
import lodash from 'lodash'
function sleep (ms) { const Common = {
return new Promise((resolve) => setTimeout(resolve, ms))
}
export default {
render, render,
cfg: Cfg.get, cfg: Cfg.get,
sleep sleep (ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
},
async getNoteQQUids (e) {
let ret = {}
if (Version.isV3) {
if (e.runtime) {
let noteCks = await e.runtime?.gsCfg?.getBingCk() || {}
lodash.forEach(noteCks, (cks, qq) => {
lodash.forEach(cks, (ck) => {
let { qq, uid } = ck
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) {
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) {
// 获取ck用户列表
let noteUids = await Common.getNoteQQUids(e)
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)
if (uid && !uidMap[uid]) {
ret[qq] = {
uid,
type: 'bind'
}
uidMap[uid] = qq
}
}
return ret
}
} }
export default Common

View File

@ -68,7 +68,7 @@ export const characters = {
10000072: ['坎蒂丝', 'Candace', '坎迪斯'], 10000072: ['坎蒂丝', 'Candace', '坎迪斯'],
10000073: ['纳西妲', 'Nahida', '草神', '小吉祥', '大吉祥', '小草神', '大慈树王', '小吉祥草王', '草萝莉', '羽毛球', '摩诃善法大吉祥智慧主', '智慧主', '智慧之神', '布耶尔'], 10000073: ['纳西妲', 'Nahida', '草神', '小吉祥', '大吉祥', '小草神', '大慈树王', '小吉祥草王', '草萝莉', '羽毛球', '摩诃善法大吉祥智慧主', '智慧主', '智慧之神', '布耶尔'],
10000074: ['莱依拉', 'Layla', '莱依菈', '来依菈', '来依拉'], 10000074: ['莱依拉', 'Layla', '莱依菈', '来依菈', '来依拉'],
10000075: ['流浪者', 'Wanderer', '散兵', '国崩', '雷电国崩', '大炮', '雷电大炮', '雷大炮', '伞兵', '斯卡拉姆齐', '七叶寂照秘密主', '正机之神'], 10000075: ['流浪者', 'Wanderer', '散兵', '国崩', '雷电国崩', '大炮', '雷电大炮', '雷大炮', '伞兵', '斯卡拉姆齐', '七叶寂照秘密主'],
10000076: ['珐露珊', 'Faruzan', '法露珊', '法璐珊', '法露姗', '法璐姗', '珐露姗', '珐璐姗'], 10000076: ['珐露珊', 'Faruzan', '法露珊', '法璐珊', '法露姗', '法璐姗', '珐露姗', '珐璐姗'],
// 自定义角色 // 自定义角色

View File

@ -1,6 +1,6 @@
import lodash from 'lodash' import lodash from 'lodash'
import moment from 'moment' import moment from 'moment'
import { Common, Profile } from '../components/index.js' import { Common } from '../components/index.js'
export default class ProfileRank { export default class ProfileRank {
constructor (data) { constructor (data) {
@ -149,36 +149,6 @@ export default class ProfileRank {
if (charId === '') { if (charId === '') {
await redis.del(`miao:rank:${groupId}:cfg`) await redis.del(`miao:rank:${groupId}:cfg`)
} }
let getUid = async function (qq) {
let uidReg = /[1-9][0-9]{8}/
let nCookie = global.NoteCookie || false
if (nCookie && nCookie[qq]) {
let nc = nCookie[qq]
if (nc.uid && uidReg.test(nc.uid)) {
return nc.uid
}
}
let uid = await redis.get(`Yz:genshin:mys:qq-uid:${qq}`)
if (uid && uidReg.test(uid)) {
return uid
}
}
for (let qq of groupMemList) {
let uid = await getUid(qq)
if (!uid) { continue }
let rankObj = await ProfileRank.create({ groupId, uid, qq})
if (charId === ''){
await Profile.forEach(uid, async function (profile) {
await rankObj.getRank(profile, true)
});
}
else {
let profile = Profile.get(uid, charId)
await rankObj.getRank(profile, true)
}
}
} }
static async getGroupCfg (groupId) { static async getGroupCfg (groupId) {
@ -208,7 +178,7 @@ export default class ProfileRank {
return ret return ret
} }
static async setRankLimit (uid, profiles, isSelfUid = false) { static async setRankUidInfo ({ uid, qq, profiles, uidType = 'bind' }) {
if (!uid) { if (!uid) {
return false return false
} }
@ -233,11 +203,20 @@ export default class ProfileRank {
} catch (e) { } catch (e) {
data = {} data = {}
} }
await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify({ data.totalCount = totalCount
totalCount, data.basicCount = basicCount
basicCount, if (data.isSelfUid) {
isSelfUid: !!(isSelfUid || data?.isSelfUid) delete data.isSelfUid
}), { EX: 3600 * 24 * 365 }) data.uidType = 'ck'
}
if (uidType === 'ck') {
data.qq = qq || data.qq || ''
data.uidType = 'ck'
} else {
data.qq = data.qq || qq || ''
data.uidType = data.uidType || 'bind'
}
await redis.set(`miao:rank:uid-info:${uid}`, JSON.stringify(data), { EX: 3600 * 24 * 365 })
} }
/** /**
@ -260,7 +239,7 @@ 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.isSelfUid) { if (data.isSelfUid || data.uidType === 'ck') {
return true return true
} }
if (rankLimit === 2) { if (rankLimit === 2) {