一些已知问题修正

This commit is contained in:
Kokomi 2023-05-31 03:19:27 +08:00
parent 26051e1f89
commit 8d0b1642c6
13 changed files with 69 additions and 88 deletions

View File

@ -13,6 +13,8 @@ import MysApi from '../../plugins/genshin/model/mys/mysApi.js'
import MysInfo from '../../plugins/genshin/model/mys/mysInfo.js' import MysInfo from '../../plugins/genshin/model/mys/mysInfo.js'
import puppeteer from '../puppeteer/puppeteer.js' import puppeteer from '../puppeteer/puppeteer.js'
import { Version } from '#miao' import { Version } from '#miao'
import NoteUser from '../../plugins/genshin/model/mys/NoteUser.js'
import MysUser from '../../plugins/genshin/model/mys/MysUser.js'
/** /**
* 常用的处理方法 * 常用的处理方法
@ -56,6 +58,14 @@ export default class Runtime {
return MysInfo return MysInfo
} }
get NoteUser () {
return NoteUser
}
get MysUser () {
return MysUser
}
static async init (e) { static async init (e) {
e.runtime = new Runtime(e) e.runtime = new Runtime(e)
e.user = await MysInfo.getNoteUser(e) e.user = await MysInfo.getNoteUser(e)

View File

@ -1,11 +1,15 @@
import plugin from '../../../lib/plugins/plugin.js' import plugin from '../../../lib/plugins/plugin.js'
import { PayData, renderImg } from '../model/payLogData.js' import { PayData, renderImg } from '../model/payLogData.js'
import NoteUser from '../model/mys/NoteUser.js'
import url from 'url' import url from 'url'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import yaml from 'yaml' import yaml from 'yaml'
export class payLog extends plugin { export class payLog extends plugin {
dirPath = path.resolve('./data/payLog/')
authKey = ''
constructor () { constructor () {
super({ super({
name: '充值记录', name: '充值记录',
@ -34,9 +38,6 @@ export class payLog extends plugin {
}) })
} }
dirPath = path.resolve('./data/payLog/')
authKey = ''
async payLog (e) { async payLog (e) {
// 判断是否存有已经生成的数据 // 判断是否存有已经生成的数据
if (!fs.readdirSync(this.dirPath, 'utf-8').includes(e.user_id + '.yaml')) { if (!fs.readdirSync(this.dirPath, 'utf-8').includes(e.user_id + '.yaml')) {
@ -146,17 +147,9 @@ export class payLog extends plugin {
} }
/** 判断主uid若没有则返回false,有则返回主uid */ /** 判断主uid若没有则返回false,有则返回主uid */
async isMain (id) { async isMain (id, game = 'gs') {
const ckPath = path.resolve('./data/MysCookie') let user = await NoteUser.create(id)
if (fs.readdirSync(ckPath, 'utf-8').includes(id + '.yaml')) { return user.getSelfUid(game)
let ck = fs.readFileSync(ckPath + `/${id}.yaml`, 'utf-8')
ck = yaml.parse(ck)
for (let k in ck) {
if (ck[k].isMain) return k
}
} else {
return false
}
} }
/** 存储数据 */ /** 存储数据 */

View File

@ -58,10 +58,6 @@ export class role extends plugin {
/** 初始化配置文件 */ /** 初始化配置文件 */
async init () { async init () {
let file = './data/MysCookie'
if (!fs.existsSync(file)) {
fs.mkdirSync(file)
}
let pubCk = './plugins/genshin/config/mys.pubCk.yaml' let pubCk = './plugins/genshin/config/mys.pubCk.yaml'
if (!fs.existsSync(pubCk)) { if (!fs.existsSync(pubCk)) {

View File

@ -4,6 +4,8 @@ import fs from 'node:fs'
import { promisify } from 'node:util' import { promisify } from 'node:util'
import lodash from 'lodash' import lodash from 'lodash'
import MysInfo from './mys/mysInfo.js' import MysInfo from './mys/mysInfo.js'
import NoteUser from './mys/NoteUser.js'
import MysUser from './mys/MysUser.js'
/** 配置文件 */ /** 配置文件 */
class GsCfg { class GsCfg {
@ -22,6 +24,10 @@ class GsCfg {
this.ignore = ['mys.pubCk', 'gacha.set', 'bot.help', 'role.name'] this.ignore = ['mys.pubCk', 'gacha.set', 'bot.help', 'role.name']
} }
get element () {
return { ...this.getdefSet('element', 'role'), ...this.getdefSet('element', 'weapon') }
}
/** /**
* @param app 功能 * @param app 功能
* @param name 配置文件名称 * @param name 配置文件名称
@ -88,65 +94,40 @@ class GsCfg {
this.watcher[type][key] = watcher this.watcher[type][key] = watcher
} }
get element () {
return { ...this.getdefSet('element', 'role'), ...this.getdefSet('element', 'weapon') }
}
/** 读取所有用户绑定的ck */ /** 读取所有用户绑定的ck */
async getBingCk () { async getBingCk (game = 'gs') {
let ck = {} let ck = {}
let ckQQ = {} let ckQQ = {}
let noteCk = {} let noteCk = {}
let dir = './data/MysCookie/'
let files = fs.readdirSync(dir).filter(file => file.endsWith('.yaml'))
const readFile = promisify(fs.readFile) await NoteUser.forEach(async function (user) {
let qq = user.qq + ''
let promises = [] let tmp = {}
lodash.forEach(user.mysUsers, (mys) => {
files.forEach((v) => promises.push(readFile(`${dir}${v}`, 'utf8'))) let uids = mys.getUids(game)
lodash.forEach(uids, (uid) => {
const res = await Promise.all(promises) let ckData = mys.getCkInfo(game)
ckData.qq = qq
res.forEach((v) => { if (!ck[uid]) {
let tmp = YAML.parse(v) ck[uid] = ckData
let qq ckQQ[qq] = ckData
lodash.forEach(tmp, (item, uid) => {
qq = item.qq
ck[String(uid)] = item
if (item.isMain && !ckQQ[String(item.qq)]) {
ckQQ[String(item.qq)] = item
} }
tmp[uid] = ckData
}) })
if (qq && !ckQQ[String(qq)]) {
ckQQ[String(qq)] = Object.values(tmp)[0]
}
noteCk[String(qq)] = tmp
}) })
noteCk[qq] = tmp
})
return { ck, ckQQ, noteCk } return { ck, ckQQ, noteCk }
} }
/** 获取qq号绑定ck */ /** 获取qq号绑定ck */
getBingCkSingle (userId) { getBingCkSingle (userId) {
let file = `./data/MysCookie/${userId}.yaml` console.log('gsCfg.getBingCkSingle() 即将废弃')
try {
let ck = fs.readFileSync(file, 'utf-8')
ck = YAML.parse(ck)
return ck
} catch (error) {
return {} return {}
} }
}
saveBingCk (userId, data) { saveBingCk (userId, data) {
let file = `./data/MysCookie/${userId}.yaml` console.log('gsCfg.saveBingCk() 即将废弃')
if (lodash.isEmpty(data)) {
fs.existsSync(file) && fs.unlinkSync(file)
} else {
let yaml = YAML.stringify(data)
fs.writeFileSync(file, yaml, 'utf8')
}
} }
/** /**

View File

@ -249,7 +249,6 @@ export default class MysUser extends BaseModel {
// 不建议使用,为了兼容老数据格式,后续废弃 // 不建议使用,为了兼容老数据格式,后续废弃
getCkInfo (game = 'gs') { getCkInfo (game = 'gs') {
let gameKey = this.gameKey(game)
return { return {
ck: this.ck, ck: this.ck,
uid: this.getUid(game), uid: this.getUid(game),

View File

@ -97,7 +97,7 @@ export default class NoteUser extends BaseModel {
static async forEach (fn) { static async forEach (fn) {
let dbs = await UserDB.findAll() let dbs = await UserDB.findAll()
await Data.forEach(users, async (db) => { await Data.forEach(dbs, async (db) => {
let user = await NoteUser.create(db.id, db) let user = await NoteUser.create(db.id, db)
return await fn(user) return await fn(user)
}) })

View File

@ -1,8 +1,8 @@
import md5 from 'md5' import md5 from 'md5'
import lodash from 'lodash'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import cfg from '../../../../lib/config/config.js' import cfg from '../../../../lib/config/config.js'
import apiTool from './apiTool.js' import apiTool from './apiTool.js'
let HttpsProxyAgent = '' let HttpsProxyAgent = ''
export default class MysApi { export default class MysApi {
/** /**
@ -11,7 +11,7 @@ export default class MysApi {
* @param option 其他参数 * @param option 其他参数
* @param option.log 是否显示日志 * @param option.log 是否显示日志
*/ */
constructor(uid, cookie, option = {}, isSr = false) { constructor (uid, cookie, option = {}, isSr = false) {
this.uid = uid this.uid = uid
this.cookie = cookie this.cookie = cookie
this.isSr = isSr this.isSr = isSr
@ -26,8 +26,14 @@ export default class MysApi {
} }
} }
getUrl(type, data = {}) { /* eslint-disable quotes */
let urlMap = this.apiTool.getUrlMap({...data,deviceId:this.device}) get device () {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device
}
getUrl (type, data = {}) {
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
if (!urlMap[type]) return false if (!urlMap[type]) return false
let { url, query = '', body = '', sign = '' } = urlMap[type] let { url, query = '', body = '', sign = '' } = urlMap[type]
@ -40,7 +46,7 @@ export default class MysApi {
return { url, headers, body } return { url, headers, body }
} }
getServer() { getServer () {
let uid = this.uid let uid = this.uid
switch (String(uid)[0]) { switch (String(uid)[0]) {
case '1': case '1':
@ -60,7 +66,7 @@ export default class MysApi {
return 'cn_gf01' return 'cn_gf01'
} }
async getData(type, data = {}, cached = false) { async getData (type, data = {}, cached = false) {
let { url, headers, body } = this.getUrl(type, data) let { url, headers, body } = this.getUrl(type, data)
if (!url) return false if (!url) return false
@ -153,9 +159,9 @@ export default class MysApi {
} }
} }
getDs(q = '', b = '') { getDs (q = '', b = '') {
let n = '' let n = ''
if (['cn_gf01', 'cn_qd01','prod_gf_cn','prod_qd_cn'].includes(this.server)) { if (['cn_gf01', 'cn_qd01', 'prod_gf_cn', 'prod_qd_cn'].includes(this.server)) {
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs' n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
} else if (/os_|official/.test(this.server)) { } else if (/os_|official/.test(this.server)) {
n = 'okr4obncj8bw5a65hbnn5oo6ixjc3l9w' n = 'okr4obncj8bw5a65hbnn5oo6ixjc3l9w'
@ -174,22 +180,16 @@ export default class MysApi {
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4()) return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
} }
cacheKey(type, data) { cacheKey (type, data) {
return 'Yz:genshin:mys:cache:' + md5(this.uid + type + JSON.stringify(data)) return 'Yz:genshin:mys:cache:' + md5(this.uid + type + JSON.stringify(data))
} }
async cache(res, cacheKey) { async cache (res, cacheKey) {
if (!res || res.retcode !== 0) return if (!res || res.retcode !== 0) return
redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res)) redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res))
} }
/* eslint-disable quotes */ async getAgent () {
get device() {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device
}
async getAgent() {
let proxyAddress = cfg.bot.proxyAddress let proxyAddress = cfg.bot.proxyAddress
if (!proxyAddress) return null if (!proxyAddress) return null
if (proxyAddress === 'http://0.0.0.0:0') return null if (proxyAddress === 'http://0.0.0.0:0') return null

View File

@ -16,13 +16,15 @@ export default class Note extends base {
} }
async getData () { async getData () {
let seed_id=lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789',16).replace(/,/g, '') let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '')
let device_fp=await MysInfo.get(this.e, 'getFp',{ let device_fp = await MysInfo.get(this.e, 'getFp', {
seed_id seed_id
}) })
let res = await MysInfo.get(this.e, 'dailyNote',{headers:{ let res = await MysInfo.get(this.e, 'dailyNote', {
'x-rpc-device_fp':device_fp?.data?.device_fp headers: {
}}) 'x-rpc-device_fp': device_fp?.data?.device_fp
}
})
let resUser let resUser
if (!res || res.retcode !== 0) return false if (!res || res.retcode !== 0) return false
@ -33,7 +35,7 @@ export default class Note extends base {
if (this.e.isSr) { if (this.e.isSr) {
screenData.tplFile = './plugins/genshin/resources/StarRail/html/dailyNote/dailyNote.html' screenData.tplFile = './plugins/genshin/resources/StarRail/html/dailyNote/dailyNote.html'
resUser = await MysInfo.get(this.e, 'UserGame') resUser = await MysInfo.get(this.e, 'UserGame')
resUser.data?.list?.forEach(v=> this.e.uid.includes(v.game_biz) ) resUser.data?.list?.forEach(v => this.e.uid.includes(v.game_biz))
if (!resUser || resUser.retcode !== 0) return false if (!resUser || resUser.retcode !== 0) return false
} }
return { return {

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB