This commit is contained in:
bbaban 2023-10-12 12:24:30 +08:00
parent a70b384580
commit 3b18140992
4 changed files with 56 additions and 56 deletions

View File

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

View File

@ -11,7 +11,7 @@ export default class MysApi {
* @param option 其他参数 * @param option 其他参数
* @param option.log 是否显示日志 * @param option.log 是否显示日志
*/ */
constructor(uid, cookie, option = {}, isSr = false, device = '') { constructor (uid, cookie, option = {}, isSr = false, device = '') {
this.uid = uid this.uid = uid
this.cookie = cookie this.cookie = cookie
this.isSr = isSr this.isSr = isSr
@ -28,12 +28,12 @@ export default class MysApi {
} }
/* eslint-disable quotes */ /* eslint-disable quotes */
get device() { get device () {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}` if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device return this._device
} }
getUrl(type, data = {}) { getUrl (type, data = {}) {
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device }) let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
if (!urlMap[type]) return false if (!urlMap[type]) return false
@ -47,7 +47,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':
@ -67,7 +67,7 @@ export default class MysApi {
return this.isSr ? 'prod_gf_cn' : 'cn_gf01' return this.isSr ? 'prod_gf_cn' : 'cn_gf01'
} }
async getData(type, data = {}, cached = false) { async getData (type, data = {}, cached = false) {
if (type == 'getFp') data = { seed_id: this.generateSeed(16) } if (type == 'getFp') data = { seed_id: this.generateSeed(16) }
let { url, headers, body } = this.getUrl(type, data) let { url, headers, body } = this.getUrl(type, data)
@ -81,7 +81,6 @@ export default class MysApi {
if (data.headers) { if (data.headers) {
headers = { ...headers, ...data.headers } headers = { ...headers, ...data.headers }
delete data.headers
} }
let param = { let param = {
@ -129,7 +128,7 @@ export default class MysApi {
return res return res
} }
getHeaders(query = '', body = '') { getHeaders (query = '', body = '') {
const cn = { const cn = {
app_version: '2.40.1', app_version: '2.40.1',
User_Agent: `Mozilla/5.0 (Linux; Android 12; ${this.device}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.73 Mobile Safari/537.36 miHoYoBBS/2.40.1`, User_Agent: `Mozilla/5.0 (Linux; Android 12; ${this.device}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.73 Mobile Safari/537.36 miHoYoBBS/2.40.1`,
@ -161,7 +160,7 @@ 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'
@ -174,24 +173,24 @@ export default class MysApi {
return `${t},${r},${DS}` return `${t},${r},${DS}`
} }
getGuid() { getGuid () {
function S4() { function S4 () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1) return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
} }
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))
} }
async getAgent() { 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
@ -213,7 +212,7 @@ export default class MysApi {
return null return null
} }
generateSeed(length = 16) { generateSeed (length = 16) {
const characters = '0123456789abcdef' const characters = '0123456789abcdef'
let result = '' let result = ''
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
@ -222,4 +221,3 @@ export default class MysApi {
return result return result
} }
} }

View File

@ -8,7 +8,7 @@ import DailyCache from './DailyCache.js'
export default class MysInfo { export default class MysInfo {
static tips = '请先#绑定cookie\n发送【体力帮助】查看配置教程' static tips = '请先#绑定cookie\n发送【体力帮助】查看配置教程'
constructor(e) { constructor (e) {
if (e) { if (e) {
this.e = e this.e = e
this.userId = String(e.user_id) this.userId = String(e.user_id)
@ -28,7 +28,7 @@ export default class MysInfo {
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.auth = ['dailyNote', 'bbs_sign_info', 'bbs_sign_home', 'bbs_sign', 'ys_ledger', 'compute', 'avatarSkill', 'detail', 'blueprint', 'UserGame', 'deckList', 'avatar_cardList', 'action_cardList', 'avatarInfo']
} }
static async init(e, api) { static async init (e, api) {
await MysInfo.initCache() await MysInfo.initCache()
let mysInfo = new MysInfo(e) let mysInfo = new MysInfo(e)
@ -75,7 +75,7 @@ export default class MysInfo {
* @param matchMsgUid 用于判断消息是否为uid数据 * @param matchMsgUid 用于判断消息是否为uid数据
* @returns {Promise<string|boolean|*|string>} * @returns {Promise<string|boolean|*|string>}
*/ */
static async getUid(e, matchMsgUid = true) { static async getUid (e, matchMsgUid = true) {
let user = await NoteUser.create(e) let user = await NoteUser.create(e)
if (e.uid && matchMsgUid) { if (e.uid && matchMsgUid) {
/** 没有绑定的自动绑定 */ /** 没有绑定的自动绑定 */
@ -119,7 +119,7 @@ export default class MysInfo {
* @param e * @param e
* @returns {Promise<boolean|*>} * @returns {Promise<boolean|*>}
*/ */
static async getSelfUid(e) { static async getSelfUid (e) {
let { msg = '', at = '' } = e let { msg = '', at = '' } = e
if (!msg) return false if (!msg) return false
@ -152,7 +152,7 @@ export default class MysInfo {
* @param option 配置 * @param option 配置
* @param option.log 是否显示请求日志 * @param option.log 是否显示请求日志
*/ */
static async get(e, api, data = {}, option = {}) { static async get (e, api, data = {}, option = {}) {
let mysInfo = await MysInfo.init(e, api) let mysInfo = await MysInfo.init(e, api)
if (!mysInfo.uid || !mysInfo.ckInfo.ck) return false if (!mysInfo.uid || !mysInfo.ckInfo.ck) return false
@ -221,7 +221,7 @@ export default class MysInfo {
* 初始化公共CK * 初始化公共CK
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
static async initPubCk() { static async initPubCk () {
// 初始化公共CK // 初始化公共CK
let pubCount = 0 let pubCount = 0
let pubCks = GsCfg.getConfig('mys', 'pubCk') || [] let pubCks = GsCfg.getConfig('mys', 'pubCk') || []
@ -245,7 +245,7 @@ export default class MysInfo {
* 默认会将用户CK加入查询池 * 默认会将用户CK加入查询池
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
static async initUserCk() { static async initUserCk () {
// 初始化用户缓存 // 初始化用户缓存
let userCount = 0 let userCount = 0
await MysUser.forEach(async (mys) => { await MysUser.forEach(async (mys) => {
@ -263,7 +263,7 @@ export default class MysInfo {
* @param clearData 强制初始化时是否清除已有数据 (刷新/重置) * @param clearData 强制初始化时是否清除已有数据 (刷新/重置)
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
static async initCache(force = false, clearData = false) { static async initCache (force = false, clearData = false) {
// 检查缓存标记 // 检查缓存标记
let cache = DailyCache.create() let cache = DailyCache.create()
if (!force && await cache.get('cache-ready')) { if (!force && await cache.get('cache-ready')) {
@ -286,13 +286,13 @@ export default class MysInfo {
return true return true
} }
static async getBingCkUid() { static async getBingCkUid () {
let res = await GsCfg.getBingCk() let res = await GsCfg.getBingCk()
return { ...res.ck } return { ...res.ck }
} }
// 获取uid绑定的ck信息 // 获取uid绑定的ck信息
static async checkUidBing(uid, game = 'gs') { static async checkUidBing (uid, game = 'gs') {
let ckUser = await MysUser.getByQueryUid(uid, game, true) let ckUser = await MysUser.getByQueryUid(uid, game, true)
if (ckUser && ckUser.ck) { if (ckUser && ckUser.ck) {
return ckUser return ckUser
@ -300,12 +300,12 @@ export default class MysInfo {
return false return false
} }
static async delDisable() { static async delDisable () {
return await MysUser.delDisable() return await MysUser.delDisable()
} }
/** 判断绑定ck才能查询 */ /** 判断绑定ck才能查询 */
checkAuth(api) { checkAuth (api) {
if (api === 'cookie') { if (api === 'cookie') {
return true return true
} }
@ -321,7 +321,7 @@ export default class MysInfo {
return false return false
} }
async checkReply() { async checkReply () {
if (this.e.noTips === true) return if (this.e.noTips === true) return
if (!this.uid) { if (!this.uid) {
@ -342,7 +342,7 @@ export default class MysInfo {
* @param onlySelfCk 是否只获取uid自己对应的ck为true则只获取uid对应ck若无则返回为空 * @param onlySelfCk 是否只获取uid自己对应的ck为true则只获取uid对应ck若无则返回为空
* @returns {Promise<string|string|*>} 查询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 if (this.ckUser?.ck) return this.ckUser?.ck
let mysUser = await MysUser.getByQueryUid(this.uid, game, onlySelfCk) let mysUser = await MysUser.getByQueryUid(this.uid, game, onlySelfCk)
@ -361,7 +361,7 @@ export default class MysInfo {
return this.ckUser?.ck return this.ckUser?.ck
} }
async checkCode(res, type, mysApi = {}, data = {}, isTask = false) { async checkCode (res, type, mysApi = {}, data = {}, isTask = false) {
if (!res) { if (!res) {
if (!isTask) this.e.reply('米游社接口请求失败,暂时无法查询') if (!isTask) this.e.reply('米游社接口请求失败,暂时无法查询')
return false return false
@ -439,7 +439,7 @@ export default class MysInfo {
} }
/** 删除失效ck */ /** 删除失效ck */
async delCk() { async delCk () {
if (!this.ckUser) { if (!this.ckUser) {
return false return false
} }
@ -449,7 +449,7 @@ export default class MysInfo {
} }
/** 查询次数满,今日内标记失效 */ /** 查询次数满,今日内标记失效 */
async disableToday(game = 'gs') { async disableToday (game = 'gs') {
/** 统计次数设为超限 */ /** 统计次数设为超限 */
await this.ckUser.disable(game) await this.ckUser.disable(game)
} }

View File

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