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'
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)
@ -33,7 +33,7 @@ export default class Calculator extends base {
/** 获取角色数据 */
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
@ -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 set = this.e.msg.replace(/#||星铁|养成|计算/g, '').trim()
@ -101,7 +101,7 @@ export default class Calculator extends base {
this.setSkill = setSkill
}
async getBody() {
async getBody () {
// 技能
let skillList = []
if (this.dataCharacter) {
@ -153,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: []
}
@ -165,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)
@ -194,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) {
@ -216,7 +215,6 @@ export default class Calculator extends base {
level_current: Number(this.dataCharacter.weapon.level),
level_target: Number(this.setSkill[1])
}
}
}
@ -225,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
@ -239,7 +237,7 @@ export default class Calculator extends base {
return avatarSkill.list
}
async computes(body) {
async computes (body) {
let computes = await MysInfo.get(this.e, 'compute', {
body,
headers: this.headers

View File

@ -11,7 +11,7 @@ export default class MysApi {
* @param option 其他参数
* @param option.log 是否显示日志
*/
constructor(uid, cookie, option = {}, isSr = false, device = '') {
constructor (uid, cookie, option = {}, isSr = false, device = '') {
this.uid = uid
this.cookie = cookie
this.isSr = isSr
@ -28,12 +28,12 @@ export default class MysApi {
}
/* eslint-disable quotes */
get device() {
get device () {
if (!this._device) this._device = `Yz-${md5(this.uid).substring(0, 5)}`
return this._device
}
getUrl(type, data = {}) {
getUrl (type, data = {}) {
let urlMap = this.apiTool.getUrlMap({ ...data, deviceId: this.device })
if (!urlMap[type]) return false
@ -47,7 +47,7 @@ export default class MysApi {
return { url, headers, body }
}
getServer() {
getServer () {
let uid = this.uid
switch (String(uid)[0]) {
case '1':
@ -67,7 +67,7 @@ export default class MysApi {
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) }
let { url, headers, body } = this.getUrl(type, data)
@ -81,7 +81,6 @@ export default class MysApi {
if (data.headers) {
headers = { ...headers, ...data.headers }
delete data.headers
}
let param = {
@ -129,7 +128,7 @@ export default class MysApi {
return res
}
getHeaders(query = '', body = '') {
getHeaders (query = '', body = '') {
const cn = {
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`,
@ -161,7 +160,7 @@ 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)) {
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs'
@ -174,24 +173,24 @@ export default class MysApi {
return `${t},${r},${DS}`
}
getGuid() {
function S4() {
getGuid () {
function S4 () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
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))
}
async getAgent() {
async getAgent () {
let proxyAddress = cfg.bot.proxyAddress
if (!proxyAddress) return null
if (proxyAddress === 'http://0.0.0.0:0') return null
@ -213,7 +212,7 @@ export default class MysApi {
return null
}
generateSeed(length = 16) {
generateSeed (length = 16) {
const characters = '0123456789abcdef'
let result = ''
for (let i = 0; i < length; i++) {
@ -222,4 +221,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)
@ -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']
}
static async init(e, api) {
static async init (e, api) {
await MysInfo.initCache()
let mysInfo = new MysInfo(e)
@ -75,7 +75,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 +119,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 +152,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
@ -221,7 +221,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') || []
@ -245,7 +245,7 @@ export default class MysInfo {
* 默认会将用户CK加入查询池
* @returns {Promise<void>}
*/
static async initUserCk() {
static async initUserCk () {
// 初始化用户缓存
let userCount = 0
await MysUser.forEach(async (mys) => {
@ -263,7 +263,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')) {
@ -286,13 +286,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
@ -300,12 +300,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
}
@ -321,7 +321,7 @@ export default class MysInfo {
return false
}
async checkReply() {
async checkReply () {
if (this.e.noTips === true) return
if (!this.uid) {
@ -342,7 +342,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)
@ -361,7 +361,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
@ -439,7 +439,7 @@ export default class MysInfo {
}
/** 删除失效ck */
async delCk() {
async delCk () {
if (!this.ckUser) {
return false
}
@ -449,7 +449,7 @@ export default class MysInfo {
}
/** 查询次数满,今日内标记失效 */
async disableToday(game = 'gs') {
async disableToday (game = 'gs') {
/** 统计次数设为超限 */
await this.ckUser.disable(game)
}

View File

@ -17,7 +17,7 @@ export default class Note extends base {
async getData () {
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 resUser
@ -36,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]
}
}
@ -53,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) {
@ -64,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
}
}
@ -105,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
}
}