!114 外置插件解决1034

* 优化
* fix
* 改一下
* 删除多余的fp
* fix
* 不重复生成fp
* fix
* 删log
* 外置插件解决1034
This commit is contained in:
帮帮 2023-10-12 19:00:53 +00:00 committed by Kokomi
parent 444eb45cfc
commit 5c5bf0b69e
6 changed files with 100 additions and 84 deletions

View File

@ -53,7 +53,7 @@ export default class blueprint extends base {
}
async computes (body) {
let computes = await this.mysApi.getData('blueprintCompute', body)
let computes = await this.mysApi.getData('blueprintCompute', { body })
if (!computes || computes.retcode !== 0) return false
computes = computes.data?.list
return computes

View File

@ -5,13 +5,13 @@ import lodash from 'lodash'
import gsCfg from './gsCfg.js'
export default class Calculator extends base {
constructor(e) {
constructor (e) {
super(e)
this.model = 'calculator'
this.checkMsg = `设置角色、武器、技能等级有误\n指令:${e.isSr ? '*克拉拉养成\n示例*克拉拉养成75 80 6 9 9 9\n参数为角色、武器、普攻、战技、终结技、天赋' : '#刻晴养成\n示例#刻晴养成81 90 9 9 9\n参数为角色、武器、技能等级'}`
}
async get(role) {
async get (role) {
this.role = role
/** 获取绑定uid */
let uid = await MysInfo.getUid(this.e)
@ -26,17 +26,14 @@ export default class Calculator extends base {
this.mysApi = new MysApi(uid, ck.ck, { log: true })
let seed_id = lodash.sample('abcdefghijklmnopqrstuvwxyz0123456789', 16).replace(/,/g, '')
let device_fp = await MysInfo.get(this.e, 'getFp', {
seed_id
})
let device_fp = await MysInfo.get(this.e, 'getFp')
this.headers = {
'x-rpc-device_fp': device_fp?.data?.device_fp
}
/** 获取角色数据 */
let character = await MysInfo.get(this.e, this.e.isSr ? 'avatarInfo' : 'character', {
headers: this.headers,
headers: this.headers
})
if (!character || character.retcode !== 0) return false
character = character.data
@ -66,7 +63,7 @@ export default class Calculator extends base {
}
}
async getSet() {
async getSet () {
let defSetSkill = this.e.isSr ? '80,80,6,10,10,10'.split(',') : '90,90,10,10,10'.split(',')
let set = this.e.msg.replace(/#||星铁|养成|计算/g, '').trim()
@ -104,7 +101,7 @@ export default class Calculator extends base {
this.setSkill = setSkill
}
async getBody() {
async getBody () {
// 技能
let skillList = []
if (this.dataCharacter) {
@ -156,7 +153,7 @@ export default class Calculator extends base {
avatar: {
item_id: Number(this.role.roleId),
cur_level: Number(this.dataCharacter.level),
target_level: Number(this.setSkill[0]),
target_level: Number(this.setSkill[0])
},
skill_list: []
}
@ -168,7 +165,6 @@ export default class Calculator extends base {
}
if (Number(this.setSkill[0]) >= data.min_level_limit) body.skill_list.push(skill)
}
} else {
skillList = skillList.filter((item) => item.max_level != 1)
@ -197,7 +193,7 @@ export default class Calculator extends base {
}
if (this.mysApi.getServer().startsWith('os')) {
body.lang = "zh-cn"
body.lang = 'zh-cn'
}
if (this.e.isSr) {
@ -219,7 +215,6 @@ export default class Calculator extends base {
level_current: Number(this.dataCharacter.weapon.level),
level_target: Number(this.setSkill[1])
}
}
}
@ -228,7 +223,7 @@ export default class Calculator extends base {
return body
}
async getSkillId(roleId) {
async getSkillId (roleId) {
let avatarSkill = await MysInfo.get(this.e, 'avatarSkill', {
headers: this.headers,
avatar_id: roleId
@ -242,8 +237,11 @@ export default class Calculator extends base {
return avatarSkill.list
}
async computes(body) {
let computes = await MysInfo.get(this.e, 'compute', body)
async computes (body) {
let computes = await MysInfo.get(this.e, 'compute', {
body,
headers: this.headers
})
if (!computes || computes.retcode !== 0) return false
computes = computes.data

View File

@ -66,11 +66,11 @@ export default class apiTool {
/** 养成计算器 */
compute: {
url: `${host}event/e20200928calculate/v2/compute`,
body: data
body: data.body
},
blueprintCompute: {
url: `${host}event/e20200928calculate/v1/furniture/compute`,
body: data
body: data.body
},
/** 养成计算器 */
blueprint: {
@ -178,7 +178,7 @@ export default class apiTool {
compute: {
url: `${host}event/rpgcalc/compute?`,
query:`game=hkrpg`,
body: data
body: data.body
},
/** 详情 */
detail: {
@ -197,7 +197,7 @@ export default class apiTool {
urlMap.genshin.blueprint.url = 'https://sg-public-api.hoyolab.com/event/calculateos/furniture/blueprint'
urlMap.genshin.blueprint.query = `share_code=${data.share_code}&region=${this.server}&lang=zh-cn`
urlMap.genshin.blueprintCompute.url = 'https://sg-public-api.hoyolab.com/event/calculateos/furniture/compute'
urlMap.genshin.blueprintCompute.body = { lang: 'zh-cn', ...data }
urlMap.genshin.blueprintCompute.body = { lang: 'zh-cn', ...data.body }
urlMap.genshin.ys_ledger.url = 'https://hk4e-api-os.mihoyo.com/event/ysledgeros/month_info'// 支持了国际服札记
urlMap.genshin.ys_ledger.query = `lang=zh-cn&month=${data.month}&uid=${this.uid}&region=${this.server}`
urlMap.genshin.useCdk.url = 'https://sg-hk4e-api.hoyoverse.com/common/apicdkey/api/webExchangeCdkey'

View File

@ -10,6 +10,8 @@ export default class MysApi {
* @param cookie 米游社cookie
* @param option 其他参数
* @param option.log 是否显示日志
* @param isSr 是否星铁
* @param device 设备device_id
*/
constructor (uid, cookie, option = {}, isSr = false, device = '') {
this.uid = uid
@ -37,12 +39,12 @@ export default class MysApi {
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
if (!urlMap[type]) return false
let { url, query = '', body = '', sign = '' } = urlMap[type]
let { url, query = '', body = '' } = urlMap[type]
if (query) url += `?${query}`
if (body) body = JSON.stringify(body)
let headers = this.getHeaders(query, body, sign)
let headers = this.getHeaders(query, body)
return { url, headers, body }
}
@ -64,26 +66,11 @@ export default class MysApi {
case '9':
return this.isSr ? 'prod_official_cht' : 'os_cht' // 港澳台服
}
return 'cn_gf01'
return this.isSr ? 'prod_gf_cn' : 'cn_gf01'
}
async getData (type, data = {}, cached = false, isGetFP = false) {
if (!isGetFP && !data.device_fp) {
let seed_id = this.generateSeed(16)
let device_fp = await this.getData('getFp', {
seed_id
}, false, true)
if (!data) {
data = {}
}
if (data?.headers) {
data.headers['x-rpc-device_fp'] = device_fp?.data?.device_fp
} else {
data.headers = {
'x-rpc-device_fp': device_fp?.data?.device_fp
}
}
}
async getData (type, data = {}, cached = false) {
if (type == 'getFp') data = { seed_id: this.generateSeed(16) }
let { url, headers, body } = this.getUrl(type, data)
if (!url) return false
@ -96,7 +83,6 @@ export default class MysApi {
if (data.headers) {
headers = { ...headers, ...data.headers }
delete data.headers
}
let param = {
@ -237,4 +223,3 @@ export default class MysApi {
return result
}
}

View File

@ -8,7 +8,7 @@ import DailyCache from './DailyCache.js'
export default class MysInfo {
static tips = '请先#绑定cookie\n发送【体力帮助】查看配置教程'
constructor(e) {
constructor (e) {
if (e) {
this.e = e
this.userId = String(e.user_id)
@ -26,9 +26,11 @@ export default class MysInfo {
// ck对应MysUser对象
this.ckUser = null
this.auth = ['dailyNote', 'bbs_sign_info', 'bbs_sign_home', 'bbs_sign', 'ys_ledger', 'compute', 'avatarSkill', 'detail', 'blueprint', 'UserGame', 'deckList', 'avatar_cardList', 'action_cardList', 'avatarInfo']
this.gtest = false
}
static async init(e, api) {
static async init (e, api) {
await MysInfo.initCache()
let mysInfo = new MysInfo(e)
@ -75,7 +77,7 @@ export default class MysInfo {
* @param matchMsgUid 用于判断消息是否为uid数据
* @returns {Promise<string|boolean|*|string>}
*/
static async getUid(e, matchMsgUid = true) {
static async getUid (e, matchMsgUid = true) {
let user = await NoteUser.create(e)
if (e.uid && matchMsgUid) {
/** 没有绑定的自动绑定 */
@ -119,7 +121,7 @@ export default class MysInfo {
* @param e
* @returns {Promise<boolean|*>}
*/
static async getSelfUid(e) {
static async getSelfUid (e) {
let { msg = '', at = '' } = e
if (!msg) return false
@ -152,7 +154,7 @@ export default class MysInfo {
* @param option 配置
* @param option.log 是否显示请求日志
*/
static async get(e, api, data = {}, option = {}) {
static async get (e, api, data = {}, option = {}) {
let mysInfo = await MysInfo.init(e, api)
if (!mysInfo.uid || !mysInfo.ckInfo.ck) return false
@ -161,10 +163,35 @@ export default class MysInfo {
let user = e.user?.getMysUser()
let mysApi = new MysApi(mysInfo.uid, mysInfo.ckInfo.ck, option, e.isSr, user.device)
let devicefp = ''
if (!data?.headers?.['x-rpc-device_fp'] && api !== 'getFp') {
devicefp = (await mysApi.getData('getFp')).data?.device_fp
if (data?.headers) {
data.headers['x-rpc-device_fp'] = devicefp
} else {
if (!data) data = {}
data.headers = {
'x-rpc-device_fp': devicefp
}
}
}
let res
if (lodash.isObject(api)) {
let all = []
/** 同步请求 */
for (let i in api) {
if (!api[i]?.headers?.['x-rpc-device_fp']) {
if (api[i]?.headers) {
api[i].headers['x-rpc-device_fp'] = devicefp
} else {
if (!api[i]) api[i] = {}
api[i].headers = {
'x-rpc-device_fp': devicefp
}
}
}
}
if (e.apiSync) {
res = []
for (let i in api) {
@ -179,6 +206,7 @@ export default class MysInfo {
for (let i in res) {
res[i] = await mysInfo.checkCode(res[i], res[i].api, mysApi, api[res[i].api])
mysInfo.gtest = true
if (res[i]?.retcode === 0) continue
@ -196,7 +224,7 @@ export default class MysInfo {
* 初始化公共CK
* @returns {Promise<void>}
*/
static async initPubCk() {
static async initPubCk () {
// 初始化公共CK
let pubCount = 0
let pubCks = GsCfg.getConfig('mys', 'pubCk') || []
@ -220,7 +248,7 @@ export default class MysInfo {
* 默认会将用户CK加入查询池
* @returns {Promise<void>}
*/
static async initUserCk() {
static async initUserCk () {
// 初始化用户缓存
let userCount = 0
await MysUser.forEach(async (mys) => {
@ -238,7 +266,7 @@ export default class MysInfo {
* @param clearData 强制初始化时是否清除已有数据 (刷新/重置)
* @returns {Promise<boolean>}
*/
static async initCache(force = false, clearData = false) {
static async initCache (force = false, clearData = false) {
// 检查缓存标记
let cache = DailyCache.create()
if (!force && await cache.get('cache-ready')) {
@ -261,13 +289,13 @@ export default class MysInfo {
return true
}
static async getBingCkUid() {
static async getBingCkUid () {
let res = await GsCfg.getBingCk()
return { ...res.ck }
}
// 获取uid绑定的ck信息
static async checkUidBing(uid, game = 'gs') {
static async checkUidBing (uid, game = 'gs') {
let ckUser = await MysUser.getByQueryUid(uid, game, true)
if (ckUser && ckUser.ck) {
return ckUser
@ -275,12 +303,12 @@ export default class MysInfo {
return false
}
static async delDisable() {
static async delDisable () {
return await MysUser.delDisable()
}
/** 判断绑定ck才能查询 */
checkAuth(api) {
checkAuth (api) {
if (api === 'cookie') {
return true
}
@ -296,7 +324,7 @@ export default class MysInfo {
return false
}
async checkReply() {
async checkReply () {
if (this.e.noTips === true) return
if (!this.uid) {
@ -317,7 +345,7 @@ export default class MysInfo {
* @param onlySelfCk 是否只获取uid自己对应的ck为true则只获取uid对应ck若无则返回为空
* @returns {Promise<string|string|*>} 查询ck获取失败则返回空
*/
async getCookie(game = 'gs', onlySelfCk = false) {
async getCookie (game = 'gs', onlySelfCk = false) {
if (this.ckUser?.ck) return this.ckUser?.ck
let mysUser = await MysUser.getByQueryUid(this.uid, game, onlySelfCk)
@ -336,7 +364,7 @@ export default class MysInfo {
return this.ckUser?.ck
}
async checkCode(res, type, mysApi = {}, data = {}, isTask = false) {
async checkCode (res, type, mysApi = {}, data = {}, isTask = false) {
if (!res) {
if (!isTask) this.e.reply('米游社接口请求失败,暂时无法查询')
return false
@ -391,8 +419,14 @@ export default class MysInfo {
if (res.api === 'detail') res.retcode = 0
break
case 1034:
logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`)
if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试')
try {
res = await Gtest.getvali(mysApi, type, data, this.gtest)
} catch (error) { }
if (!res || res?.retcode == 1034) {
logger.mark(`[米游社查询失败][uid:${this.uid}][qq:${this.userId}] 遇到验证码`)
if (!isTask) this.e.reply('米游社查询遇到验证码,请稍后再试')
}
break
default:
if (!isTask) this.e.reply(`米游社接口报错,暂时无法查询:${res.message || 'error'}`)
@ -407,7 +441,7 @@ export default class MysInfo {
}
/** 删除失效ck */
async delCk() {
async delCk () {
if (!this.ckUser) {
return false
}
@ -417,7 +451,7 @@ export default class MysInfo {
}
/** 查询次数满,今日内标记失效 */
async disableToday(game = 'gs') {
async disableToday (game = 'gs') {
/** 统计次数设为超限 */
await this.ckUser.disable(game)
}

View File

@ -16,15 +16,10 @@ 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', {
seed_id
})
let res = await MysInfo.get(this.e, 'dailyNote', {
headers: {
'x-rpc-device_fp': device_fp?.data?.device_fp
}
})
let device_fp = await MysInfo.get(this.e, 'getFp')
let headers = { 'x-rpc-device_fp': device_fp?.data?.device_fp }
let res = await MysInfo.get(this.e, 'dailyNote', { headers })
let resUser
if (!res || res.retcode !== 0) return false
@ -33,7 +28,7 @@ export default class Note extends base {
let screenData = this.screenData
if (this.e.isSr) {
resUser = await MysInfo.get(this.e, 'UserGame')
resUser = await MysInfo.get(this.e, 'UserGame', { headers })
resUser.data?.list?.forEach(v => this.e.uid.includes(v.game_biz))
if (!resUser || resUser.retcode !== 0) return false
}
@ -41,7 +36,8 @@ export default class Note extends base {
name: this.e.sender.card,
quality: 80,
...screenData,
...data, ...resUser?.data?.list[0]
...data,
...resUser?.data?.list[0]
}
}
@ -58,7 +54,7 @@ export default class Note extends base {
let minutes = d.minutes()
let seconds = d.seconds()
resinMaxTime = hours + '小时' + minutes + '分钟' + seconds + '秒'
//精确到秒。。。。
// 精确到秒。。。。
if (day > 0) {
resinMaxTime = day + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒'
} else if (hours > 0) {
@ -69,17 +65,17 @@ export default class Note extends base {
resinMaxTime = seconds + '秒'
}
if ((day > 0) || (hours > 0) || (seconds > 0)) {
let total_seconds = 3600*hours + 60*minutes + seconds
const now = new Date()
const dateTimes = now.getTime() + total_seconds * 1000
const date = new Date(dateTimes)
const dayDiff = date.getDate() - now.getDate()
const str = dayDiff === 0 ? '今日' : '明日'
const timeStr = `${date.getHours().toString().padStart(2, '0')}:${date
let total_seconds = 3600 * hours + 60 * minutes + seconds
const now = new Date()
const dateTimes = now.getTime() + total_seconds * 1000
const date = new Date(dateTimes)
const dayDiff = date.getDate() - now.getDate()
const str = dayDiff === 0 ? '今日' : '明日'
const timeStr = `${date.getHours().toString().padStart(2, '0')}:${date
.getMinutes()
.toString()
.padStart(2, '0')}`
let recoverTimeStr = ` | [${str}]${timeStr}`
let recoverTimeStr = ` | [${str}]${timeStr}`
resinMaxTime += recoverTimeStr
}
}
@ -110,8 +106,11 @@ export default class Note extends base {
let day = `${week[moment().day()]}`
return {
uid: this.e.uid,
saveId: this.e.uid, icon, day,
resinMaxTime, nowDay: moment(new Date()).format('YYYY年MM月DD日'),
saveId: this.e.uid,
icon,
day,
resinMaxTime,
nowDay: moment(new Date()).format('YYYY年MM月DD日'),
...data
}
}