mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-16 04:35:42 +00:00
优化mys天赋的请求逻辑,防止频繁触发验证码提示
This commit is contained in:
parent
84f50afd91
commit
07b9c22a55
@ -74,10 +74,11 @@ export default class Player extends Base {
|
|||||||
this.setBasicData(data)
|
this.setBasicData(data)
|
||||||
if (data.chars) {
|
if (data.chars) {
|
||||||
this.setAvatars(data.chars)
|
this.setAvatars(data.chars)
|
||||||
// 暂时保留旧数据,防止异常情况
|
|
||||||
this._chars = data.chars
|
|
||||||
}
|
}
|
||||||
this.setAvatars(data.avatars || [])
|
this.setAvatars(data.avatars || [])
|
||||||
|
if (data._ck) {
|
||||||
|
this._ck = data._ck
|
||||||
|
}
|
||||||
if (!data.avatars) {
|
if (!data.avatars) {
|
||||||
this.save()
|
this.save()
|
||||||
}
|
}
|
||||||
@ -100,9 +101,8 @@ export default class Player extends Base {
|
|||||||
this.forEachAvatar((avatar) => {
|
this.forEachAvatar((avatar) => {
|
||||||
ret.avatars[avatar.id] = avatar.toJSON()
|
ret.avatars[avatar.id] = avatar.toJSON()
|
||||||
})
|
})
|
||||||
// 暂时保留旧数据,防止异常情况
|
if (this._ck) {
|
||||||
if (this._chars) {
|
ret._ck = this._ck
|
||||||
ret.chars = this._chars
|
|
||||||
}
|
}
|
||||||
Data.writeJSON(`/data/UserData/${this.uid}.json`, ret, '', 'root')
|
Data.writeJSON(`/data/UserData/${this.uid}.json`, ret, '', 'root')
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,23 @@ const MysAvatar = {
|
|||||||
let reqTime = forceMap[force] === 0 ? 0 : (forceMap[force] || 60)
|
let reqTime = forceMap[force] === 0 ? 0 : (forceMap[force] || 60)
|
||||||
return duration > reqTime * 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
|
* @param player
|
||||||
@ -36,9 +53,6 @@ const MysAvatar = {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let charData = await mys.getCharacter()
|
let charData = await mys.getCharacter()
|
||||||
if (!charData || !charData.avatars) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
MysAvatar.setMysCharData(player, charData)
|
MysAvatar.setMysCharData(player, charData)
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -69,46 +83,50 @@ const MysAvatar = {
|
|||||||
* @param charData
|
* @param charData
|
||||||
*/
|
*/
|
||||||
setMysCharData (player, charData) {
|
setMysCharData (player, charData) {
|
||||||
let role = charData.role
|
if (charData && charData.avatars) {
|
||||||
player.setBasicData({
|
let role = charData.role || {}
|
||||||
level: role.level,
|
player.setBasicData({
|
||||||
name: role.nickname
|
level: role.level,
|
||||||
})
|
name: role.nickname
|
||||||
let charIds = {}
|
})
|
||||||
lodash.forEach(charData.avatars, (ds) => {
|
let charIds = {}
|
||||||
let avatar = Data.getData(ds, 'id,level,cons:actived_constellation_num,fetter')
|
lodash.forEach(charData.avatars, (ds) => {
|
||||||
avatar.elem = ds.element.toLowerCase()
|
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) {
|
let costume = (ds?.costumes || [])[0]
|
||||||
avatar.costume = costume.id
|
if (costume && costume.id) {
|
||||||
}
|
avatar.costume = costume.id
|
||||||
avatar.weapon = Data.getData(ds.weapon, 'name,star:rarity,level,promote:promote_level,affix:affix_level')
|
}
|
||||||
// 处理圣遗物数据
|
avatar.weapon = Data.getData(ds.weapon, 'name,star:rarity,level,promote:promote_level,affix:affix_level')
|
||||||
let artis = {}
|
// 处理圣遗物数据
|
||||||
lodash.forEach(ds.reliquaries, (re) => {
|
let artis = {}
|
||||||
const posIdx = { 生之花: 1, 死之羽: 2, 时之沙: 3, 空之杯: 4, 理之冠: 5 }
|
lodash.forEach(ds.reliquaries, (re) => {
|
||||||
if (re && re.name && posIdx[re.pos_name]) {
|
const posIdx = { 生之花: 1, 死之羽: 2, 时之沙: 3, 空之杯: 4, 理之冠: 5 }
|
||||||
artis[posIdx[re.pos_name]] = {
|
if (re && re.name && posIdx[re.pos_name]) {
|
||||||
name: re.name,
|
artis[posIdx[re.pos_name]] = {
|
||||||
level: re.level
|
name: re.name,
|
||||||
|
level: re.level
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
avatar.artis = artis
|
||||||
avatar.artis = artis
|
player.setAvatar(avatar, 'mys')
|
||||||
player.setAvatar(avatar, 'mys')
|
charIds[avatar.id] = true
|
||||||
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]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
// 若角色数据>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) {
|
setMysInfo (player, infoData) {
|
||||||
@ -192,6 +210,7 @@ const MysAvatar = {
|
|||||||
if (!e || !mys || !mys.isSelfCookie) {
|
if (!e || !mys || !mys.isSelfCookie) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
force = MysAvatar.checkForce(player, force)
|
||||||
let needReqIds = MysAvatar.getNeedRefreshIds(player, ids, force)
|
let needReqIds = MysAvatar.getNeedRefreshIds(player, ids, force)
|
||||||
if (needReqIds.length > 0) {
|
if (needReqIds.length > 0) {
|
||||||
if (needReqIds.length > 8) {
|
if (needReqIds.length > 8) {
|
||||||
|
0
resources/meta/character/卡维/imgs/gacha.webp
Normal file
0
resources/meta/character/卡维/imgs/gacha.webp
Normal file
0
resources/meta/character/卡维/imgs/side.webp
Normal file
0
resources/meta/character/卡维/imgs/side.webp
Normal file
0
resources/meta/character/白术/imgs/gacha.webp
Normal file
0
resources/meta/character/白术/imgs/gacha.webp
Normal file
0
resources/meta/character/白术/imgs/side.webp
Normal file
0
resources/meta/character/白术/imgs/side.webp
Normal file
0
resources/meta/material/boss/常暗圆环.webp
Normal file
0
resources/meta/material/boss/常暗圆环.webp
Normal file
@ -44,25 +44,25 @@
|
|||||||
"star": 1
|
"star": 1
|
||||||
},
|
},
|
||||||
"孢囊晶尘": {
|
"孢囊晶尘": {
|
||||||
"id": 112061,
|
"id": "n112061",
|
||||||
"name": "孢囊晶尘",
|
"name": "孢囊晶尘",
|
||||||
"type": "normal",
|
"type": "normal",
|
||||||
"star": 3,
|
"star": 3,
|
||||||
"items": {
|
"items": {
|
||||||
"蕈兽孢子": {
|
"蕈兽孢子": {
|
||||||
"id": 112059,
|
"id": "n112059",
|
||||||
"name": "蕈兽孢子",
|
"name": "蕈兽孢子",
|
||||||
"type": "normal",
|
"type": "normal",
|
||||||
"star": 1
|
"star": 1
|
||||||
},
|
},
|
||||||
"荧光孢粉": {
|
"荧光孢粉": {
|
||||||
"id": 112060,
|
"id": "n112060",
|
||||||
"name": "荧光孢粉",
|
"name": "荧光孢粉",
|
||||||
"type": "normal",
|
"type": "normal",
|
||||||
"star": 2
|
"star": 2
|
||||||
},
|
},
|
||||||
"孢囊晶尘": {
|
"孢囊晶尘": {
|
||||||
"id": 112061,
|
"id": "n112061",
|
||||||
"name": "孢囊晶尘",
|
"name": "孢囊晶尘",
|
||||||
"type": "normal",
|
"type": "normal",
|
||||||
"star": 3
|
"star": 3
|
||||||
@ -1274,7 +1274,7 @@
|
|||||||
"star": 4
|
"star": 4
|
||||||
},
|
},
|
||||||
"???": {
|
"???": {
|
||||||
"id": "n113042",
|
"id": "n113046",
|
||||||
"name": "???",
|
"name": "???",
|
||||||
"type": "weekly",
|
"type": "weekly",
|
||||||
"star": 5
|
"star": 5
|
||||||
@ -2056,5 +2056,17 @@
|
|||||||
"star": 4
|
"star": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"悼灵花": {
|
||||||
|
"id": "n101223",
|
||||||
|
"name": "悼灵花",
|
||||||
|
"type": "specialty",
|
||||||
|
"star": 1
|
||||||
|
},
|
||||||
|
"常暗圆环": {
|
||||||
|
"id": "n113045",
|
||||||
|
"name": "常暗圆环",
|
||||||
|
"type": "boss",
|
||||||
|
"star": 4
|
||||||
}
|
}
|
||||||
}
|
}
|
0
resources/meta/material/specialty/悼灵花.webp
Normal file
0
resources/meta/material/specialty/悼灵花.webp
Normal file
@ -4,6 +4,9 @@ import fetch from 'node-fetch'
|
|||||||
import { Data } from '../components/index.js'
|
import { Data } from '../components/index.js'
|
||||||
import lodash from 'lodash'
|
import lodash from 'lodash'
|
||||||
import request from 'request'
|
import request from 'request'
|
||||||
|
import HttpsProxyAgent from 'https-proxy-agent'
|
||||||
|
|
||||||
|
let agent = new HttpsProxyAgent('http://localhost:4780')
|
||||||
|
|
||||||
const artiIdx = {
|
const artiIdx = {
|
||||||
Flower: 1,
|
Flower: 1,
|
||||||
@ -15,7 +18,7 @@ const artiIdx = {
|
|||||||
|
|
||||||
async function getSets (id) {
|
async function getSets (id) {
|
||||||
const url = `https://genshin.honeyhunterworld.com/i_${id}/?lang=CHS`
|
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 txt = await req.text()
|
||||||
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
||||||
let ret = {}
|
let ret = {}
|
||||||
@ -41,7 +44,7 @@ async function getSets (id) {
|
|||||||
|
|
||||||
async function down (sets = '') {
|
async function down (sets = '') {
|
||||||
const url = 'https://genshin.honeyhunterworld.com/fam_art_set/?lang=CHS'
|
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()
|
let txt = await req.text()
|
||||||
if (sets) {
|
if (sets) {
|
||||||
sets = sets.split(',')
|
sets = sets.split(',')
|
||||||
@ -52,7 +55,14 @@ async function down (sets = '') {
|
|||||||
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
||||||
if (sTxt && sTxt[1]) {
|
if (sTxt && sTxt[1]) {
|
||||||
// eslint-disable-next-line no-eval
|
// 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) => {
|
lodash.forEach(tmp, (ds) => {
|
||||||
let na = cheerio.load(ds[0])('a:last')
|
let na = cheerio.load(ds[0])('a:last')
|
||||||
let idRet = /i_(\w+)\//.exec(na.attr('href'))
|
let idRet = /i_(\w+)\//.exec(na.attr('href'))
|
||||||
|
@ -4,6 +4,9 @@ import fetch from 'node-fetch'
|
|||||||
import ImgDownloader from './sprider/ImgDown.js'
|
import ImgDownloader from './sprider/ImgDown.js'
|
||||||
import CharData from './sprider/CharData.js'
|
import CharData from './sprider/CharData.js'
|
||||||
import { Data } from '../components/index.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 mData = Data.readJSON('/resources/meta/material/data.json')
|
||||||
let tId = Data.readJSON('/tools/meta/talent.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-site': 'none',
|
||||||
'sec-fetch-user': '?1',
|
'sec-fetch-user': '?1',
|
||||||
'upgrade-insecure-requests': 1
|
'upgrade-insecure-requests': 1
|
||||||
}
|
},
|
||||||
|
agent
|
||||||
})
|
})
|
||||||
let txt = await req.text()
|
let txt = await req.text()
|
||||||
const $ = cheerio.load(txt)
|
const $ = cheerio.load(txt)
|
||||||
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
let sTxt = /sortable_data.push\((.*)\)/.exec(txt)
|
||||||
if (sTxt && sTxt[1]) {
|
if (sTxt && sTxt[1]) {
|
||||||
// eslint-disable-next-line no-eval
|
// 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) {
|
for (let idx in tmp) {
|
||||||
let t = tmp[idx].join('')
|
let t = tmp[idx].join('')
|
||||||
if (/Namecard/.test(t)) {
|
if (/Namecard/.test(t)) {
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import request from 'request'
|
import request from 'request'
|
||||||
import { Data } from '../../components/index.js'
|
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 _path = process.cwd()
|
||||||
const _root = _path + '/plugins/miao-plugin/'
|
const _root = _path + '/plugins/miao-plugin/'
|
||||||
|
Loading…
Reference in New Issue
Block a user