2022-08-18 10:13:42 +00:00
|
|
|
import Cfg from './Cfg.js'
|
2023-02-13 20:43:14 +00:00
|
|
|
import render from './common/Render.js'
|
2022-11-15 20:07:21 +00:00
|
|
|
import { Version } from './index.js'
|
|
|
|
import lodash from 'lodash'
|
2022-05-22 13:10:10 +00:00
|
|
|
|
2022-11-15 20:07:21 +00:00
|
|
|
const Common = {
|
2022-05-22 13:10:10 +00:00
|
|
|
render,
|
|
|
|
cfg: Cfg.get,
|
2022-11-15 20:07:21 +00:00
|
|
|
sleep (ms) {
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
|
|
},
|
|
|
|
|
2023-02-26 15:42:56 +00:00
|
|
|
async downFile () {
|
|
|
|
console.log('down file')
|
|
|
|
},
|
|
|
|
|
2022-11-15 20:07:21 +00:00
|
|
|
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 = {}
|
|
|
|
|
2022-11-15 20:58:19 +00:00
|
|
|
let groupMemMap = await e.group?.getMemberMap()
|
2022-11-15 20:07:21 +00:00
|
|
|
// 优先匹配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]) {
|
2022-11-15 20:25:07 +00:00
|
|
|
ret[qq] = [{
|
2022-11-15 20:07:21 +00:00
|
|
|
uid,
|
|
|
|
type: 'bind'
|
2022-11-15 20:25:07 +00:00
|
|
|
}]
|
2022-11-15 20:07:21 +00:00
|
|
|
uidMap[uid] = qq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
2022-07-23 20:32:10 +00:00
|
|
|
}
|
2022-11-15 20:07:21 +00:00
|
|
|
|
|
|
|
export default Common
|