优化mys天赋的请求逻辑,防止频繁触发验证码提示

This commit is contained in:
Kokomi 2023-03-04 06:01:11 +08:00
parent 84f50afd91
commit 07b9c22a55
12 changed files with 112 additions and 55 deletions

View File

@ -74,10 +74,11 @@ export default class Player extends Base {
this.setBasicData(data)
if (data.chars) {
this.setAvatars(data.chars)
// 暂时保留旧数据,防止异常情况
this._chars = data.chars
}
this.setAvatars(data.avatars || [])
if (data._ck) {
this._ck = data._ck
}
if (!data.avatars) {
this.save()
}
@ -100,9 +101,8 @@ export default class Player extends Base {
this.forEachAvatar((avatar) => {
ret.avatars[avatar.id] = avatar.toJSON()
})
// 暂时保留旧数据,防止异常情况
if (this._chars) {
ret.chars = this._chars
if (this._ck) {
ret._ck = this._ck
}
Data.writeJSON(`/data/UserData/${this.uid}.json`, ret, '', 'root')
}

View File

@ -19,6 +19,23 @@ const MysAvatar = {
let reqTime = forceMap[force] === 0 ? 0 : (forceMap[force] || 60)
return duration > reqTime * 60
},
checkForce (player, force) {
let e = player?.e
let mys = e?._mys
if (!e || !mys || !mys.isSelfCookie) {
return force
}
let ck = mys?.ckInfo?.ck
if (!ck || player._ck === ck) {
return force
}
player._info = 0
player._mys = 0
lodash.forEach(player._avatars, (ds) => {
ds._talent = 0
})
return 2
},
/**
* 更新米游社角色信息
* @param player
@ -36,9 +53,6 @@ const MysAvatar = {
return false
}
let charData = await mys.getCharacter()
if (!charData || !charData.avatars) {
return false
}
MysAvatar.setMysCharData(player, charData)
},
@ -69,46 +83,50 @@ const MysAvatar = {
* @param charData
*/
setMysCharData (player, charData) {
let role = charData.role
player.setBasicData({
level: role.level,
name: role.nickname
})
let charIds = {}
lodash.forEach(charData.avatars, (ds) => {
let avatar = Data.getData(ds, 'id,level,cons:actived_constellation_num,fetter')
avatar.elem = ds.element.toLowerCase()
// 处理时装数据
let costume = (ds?.costumes || [])[0]
if (costume && costume.id) {
avatar.costume = costume.id
}
avatar.weapon = Data.getData(ds.weapon, 'name,star:rarity,level,promote:promote_level,affix:affix_level')
// 处理圣遗物数据
let artis = {}
lodash.forEach(ds.reliquaries, (re) => {
const posIdx = { 生之花: 1, 死之羽: 2, 时之沙: 3, 空之杯: 4, 理之冠: 5 }
if (re && re.name && posIdx[re.pos_name]) {
artis[posIdx[re.pos_name]] = {
name: re.name,
level: re.level
if (charData && charData.avatars) {
let role = charData.role || {}
player.setBasicData({
level: role.level,
name: role.nickname
})
let charIds = {}
lodash.forEach(charData.avatars, (ds) => {
let avatar = Data.getData(ds, 'id,level,cons:actived_constellation_num,fetter')
avatar.elem = ds.element.toLowerCase()
// 处理时装数据
let costume = (ds?.costumes || [])[0]
if (costume && costume.id) {
avatar.costume = costume.id
}
avatar.weapon = Data.getData(ds.weapon, 'name,star:rarity,level,promote:promote_level,affix:affix_level')
// 处理圣遗物数据
let artis = {}
lodash.forEach(ds.reliquaries, (re) => {
const posIdx = { 生之花: 1, 死之羽: 2, 时之沙: 3, 空之杯: 4, 理之冠: 5 }
if (re && re.name && posIdx[re.pos_name]) {
artis[posIdx[re.pos_name]] = {
name: re.name,
level: re.level
}
}
}
})
avatar.artis = artis
player.setAvatar(avatar, 'mys')
charIds[avatar.id] = true
})
// 若角色数据>8检查缓存删除错误缓存的数据
if (lodash.keys(charIds).length > 8) {
player.forEachAvatar((avatar) => {
if (!charIds[avatar.id] && !avatar.isProfile) {
delete player._avatars[avatar.id]
}
})
avatar.artis = artis
player.setAvatar(avatar, 'mys')
charIds[avatar.id] = true
})
// 若角色数据>8检查缓存删除错误缓存的数据
if (lodash.keys(charIds).length > 8) {
player.forEachAvatar((avatar) => {
if (!charIds[avatar.id] && !avatar.isProfile) {
delete player._avatars[avatar.id]
}
})
}
}
if (player._avatars && !lodash.isEmpty(player._avatars)) {
player._mys = new Date() * 1
player.save()
}
player._mys = new Date() * 1
player.save()
},
setMysInfo (player, infoData) {
@ -192,6 +210,7 @@ const MysAvatar = {
if (!e || !mys || !mys.isSelfCookie) {
return false
}
force = MysAvatar.checkForce(player, force)
let needReqIds = MysAvatar.getNeedRefreshIds(player, ids, force)
if (needReqIds.length > 0) {
if (needReqIds.length > 8) {

View File

@ -44,25 +44,25 @@
"star": 1
},
"孢囊晶尘": {
"id": 112061,
"id": "n112061",
"name": "孢囊晶尘",
"type": "normal",
"star": 3,
"items": {
"蕈兽孢子": {
"id": 112059,
"id": "n112059",
"name": "蕈兽孢子",
"type": "normal",
"star": 1
},
"荧光孢粉": {
"id": 112060,
"id": "n112060",
"name": "荧光孢粉",
"type": "normal",
"star": 2
},
"孢囊晶尘": {
"id": 112061,
"id": "n112061",
"name": "孢囊晶尘",
"type": "normal",
"star": 3
@ -1274,7 +1274,7 @@
"star": 4
},
"": {
"id": "n113042",
"id": "n113046",
"name": "",
"type": "weekly",
"star": 5
@ -2056,5 +2056,17 @@
"star": 4
}
}
},
"悼灵花": {
"id": "n101223",
"name": "悼灵花",
"type": "specialty",
"star": 1
},
"常暗圆环": {
"id": "n113045",
"name": "常暗圆环",
"type": "boss",
"star": 4
}
}

View File

@ -4,6 +4,9 @@ import fetch from 'node-fetch'
import { Data } from '../components/index.js'
import lodash from 'lodash'
import request from 'request'
import HttpsProxyAgent from 'https-proxy-agent'
let agent = new HttpsProxyAgent('http://localhost:4780')
const artiIdx = {
Flower: 1,
@ -15,7 +18,7 @@ const artiIdx = {
async function getSets (id) {
const url = `https://genshin.honeyhunterworld.com/i_${id}/?lang=CHS`
let req = await fetch(url)
let req = await fetch(url, { agent })
let txt = await req.text()
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
let ret = {}
@ -41,7 +44,7 @@ async function getSets (id) {
async function down (sets = '') {
const url = 'https://genshin.honeyhunterworld.com/fam_art_set/?lang=CHS'
let req = await fetch(url)
let req = await fetch(url, { agent })
let txt = await req.text()
if (sets) {
sets = sets.split(',')
@ -52,7 +55,14 @@ async function down (sets = '') {
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
if (sTxt && sTxt[1]) {
// eslint-disable-next-line no-eval
let tmp = eval(sTxt[1])
let txt = sTxt[1]
txt = txt.replace(/<script>.+<\/script>/g, '')
let tmp
try {
tmp = eval(txt)
} catch (e) {
}
lodash.forEach(tmp, (ds) => {
let na = cheerio.load(ds[0])('a:last')
let idRet = /i_(\w+)\//.exec(na.attr('href'))

View File

@ -4,6 +4,9 @@ import fetch from 'node-fetch'
import ImgDownloader from './sprider/ImgDown.js'
import CharData from './sprider/CharData.js'
import { Data } from '../components/index.js'
import HttpsProxyAgent from 'https-proxy-agent'
let agent = new HttpsProxyAgent('http://localhost:4780')
let mData = Data.readJSON('/resources/meta/material/data.json')
let tId = Data.readJSON('/tools/meta/talent.json')
@ -27,14 +30,21 @@ let getCharData = async function (id, key, name = '', _id = id) {
'sec-fetch-site': 'none',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': 1
}
},
agent
})
let txt = await req.text()
const $ = cheerio.load(txt)
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
if (sTxt && sTxt[1]) {
// eslint-disable-next-line no-eval
let tmp = eval(sTxt[1])
let tmp
try {
tmp = eval(sTxt[1])
} catch (e) {
tmp = {}
}
for (let idx in tmp) {
let t = tmp[idx].join('')
if (/Namecard/.test(t)) {

View File

@ -1,6 +1,12 @@
import fs from 'fs'
import request from 'request'
import { Data } from '../../components/index.js'
import HttpsProxyAgent from 'https-proxy-agent'
let agent = new HttpsProxyAgent('http://localhost:4780')
request.defaults({
agent
})
const _path = process.cwd()
const _root = _path + '/plugins/miao-plugin/'