一些已知问题修正

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 puppeteer from '../puppeteer/puppeteer.js'
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
}
get NoteUser () {
return NoteUser
}
get MysUser () {
return MysUser
}
static async init (e) {
e.runtime = new Runtime(e)
e.user = await MysInfo.getNoteUser(e)

View File

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

View File

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

View File

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

View File

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

View File

@ -97,7 +97,7 @@ export default class NoteUser extends BaseModel {
static async forEach (fn) {
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)
return await fn(user)
})

View File

@ -1,8 +1,8 @@
import md5 from 'md5'
import lodash from 'lodash'
import fetch from 'node-fetch'
import cfg from '../../../../lib/config/config.js'
import apiTool from './apiTool.js'
let HttpsProxyAgent = ''
export default class MysApi {
/**
@ -11,7 +11,7 @@ export default class MysApi {
* @param option 其他参数
* @param option.log 是否显示日志
*/
constructor(uid, cookie, option = {}, isSr = false) {
constructor (uid, cookie, option = {}, isSr = false) {
this.uid = uid
this.cookie = cookie
this.isSr = isSr
@ -26,8 +26,14 @@ export default class MysApi {
}
}
getUrl(type, data = {}) {
let urlMap = this.apiTool.getUrlMap({...data,deviceId:this.device})
/* eslint-disable quotes */
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
let { url, query = '', body = '', sign = '' } = urlMap[type]
@ -40,7 +46,7 @@ export default class MysApi {
return { url, headers, body }
}
getServer() {
getServer () {
let uid = this.uid
switch (String(uid)[0]) {
case '1':
@ -60,7 +66,7 @@ export default class MysApi {
return 'cn_gf01'
}
async getData(type, data = {}, cached = false) {
async getData (type, data = {}, cached = false) {
let { url, headers, body } = this.getUrl(type, data)
if (!url) return false
@ -153,9 +159,9 @@ export default class MysApi {
}
}
getDs(q = '', b = '') {
getDs (q = '', b = '') {
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'
} else if (/os_|official/.test(this.server)) {
n = 'okr4obncj8bw5a65hbnn5oo6ixjc3l9w'
@ -174,22 +180,16 @@ export default class MysApi {
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))
}
async cache(res, cacheKey) {
async cache (res, cacheKey) {
if (!res || res.retcode !== 0) return
redis.setEx(cacheKey, this.cacheCd, JSON.stringify(res))
}
/* eslint-disable quotes */
get device() {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device
}
async getAgent() {
async getAgent () {
let proxyAddress = cfg.bot.proxyAddress
if (!proxyAddress) 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 () {
let seed_id=lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789',16).replace(/,/g, '')
let device_fp=await MysInfo.get(this.e, 'getFp',{
let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '')
let device_fp = await MysInfo.get(this.e, 'getFp', {
seed_id
})
let res = await MysInfo.get(this.e, 'dailyNote',{headers:{
'x-rpc-device_fp':device_fp?.data?.device_fp
}})
let res = await MysInfo.get(this.e, 'dailyNote', {
headers: {
'x-rpc-device_fp': device_fp?.data?.device_fp
}
})
let resUser
if (!res || res.retcode !== 0) return false
@ -33,7 +35,7 @@ export default class Note extends base {
if (this.e.isSr) {
screenData.tplFile = './plugins/genshin/resources/StarRail/html/dailyNote/dailyNote.html'
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
}
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