Miao-Yunzai/plugins/genshin/model/note.js

204 lines
6.0 KiB
JavaScript
Raw Normal View History

2023-05-09 11:03:38 +08:00
import moment from 'moment'
import lodash from 'lodash'
import base from './base.js'
import MysInfo from './mys/mysInfo.js'
2023-03-04 14:30:13 +08:00
export default class Note extends base {
2023-05-09 11:03:38 +08:00
constructor (e) {
super(e)
this.model = 'dailyNote'
2023-03-04 14:30:13 +08:00
}
/** 生成体力图片 */
2023-05-09 11:03:38 +08:00
static async get (e) {
let note = new Note(e)
return await note.getData()
2023-03-04 14:30:13 +08:00
}
2023-05-09 11:03:38 +08:00
async getData () {
2023-05-28 14:01:31 +08:00
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:{
2023-05-28 15:25:23 +08:00
'x-rpc-device_fp':device_fp?.data?.device_fp
}})
2023-05-09 11:03:38 +08:00
let resUser
if (!res || res.retcode !== 0) return false
2023-05-28 14:01:31 +08:00
2023-03-04 14:30:13 +08:00
/** 截图数据 */
2023-05-09 11:03:38 +08:00
let data = this.e.isSr ? this.noteSr(res) : this.noteData(res)
2023-05-28 14:01:31 +08:00
2023-05-09 11:03:38 +08:00
let screenData = this.screenData
if (this.e.isSr) {
2023-05-09 11:03:38 +08:00
screenData.tplFile = './plugins/genshin/resources/StarRail/html/dailyNote/dailyNote.html'
resUser = await MysInfo.get(this.e, 'UserGame')
2023-05-28 14:01:31 +08:00
resUser.data?.list?.forEach(v=> this.e.uid.includes(v.game_biz) )
2023-05-09 11:03:38 +08:00
if (!resUser || resUser.retcode !== 0) return false
}
2023-03-04 14:30:13 +08:00
return {
name: this.e.sender.card,
quality: 80,
...screenData,
2023-05-28 15:25:23 +08:00
...data, ...resUser?.data?.list[0]
2023-05-09 11:03:38 +08:00
}
}
2023-05-09 11:03:38 +08:00
noteSr (res) {
let { data } = res
let nowDay = moment().date()
let nowUnix = Number(moment().format('X'))
/** 树脂 */
2023-05-09 11:03:38 +08:00
let resinMaxTime
if (data.stamina_recover_time > 0) {
2023-05-09 11:03:38 +08:00
let d = moment.duration(data.stamina_recover_time, 'seconds')
let day = Math.floor(d.asDays())
let hours = d.hours()
let minutes = d.minutes()
let seconds = d.seconds()
resinMaxTime = hours + '小时' + minutes + '分钟' + seconds + '秒'
2023-05-06 17:41:07 +08:00
//精确到秒。。。。
2023-05-09 11:03:38 +08:00
if (day > 0) {
resinMaxTime = day + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒'
} else if (hours > 0) {
resinMaxTime = hours + '小时' + minutes + '分钟' + seconds + '秒'
} else if (minutes > 0) {
resinMaxTime = minutes + '分钟' + seconds + '秒'
} else if (seconds > 0) {
resinMaxTime = seconds + '秒'
}
}
2023-05-09 11:03:38 +08:00
data.bfStamina = data.current_stamina / data.max_stamina * 100 + '%'
/** 派遣 */
2023-05-09 11:03:38 +08:00
for (let item of data.expeditions) {
let d = moment.duration(item.remaining_time, 'seconds')
let day = Math.floor(d.asDays())
let hours = d.hours()
let minutes = d.minutes()
item.dateTime = ([day + '天', hours + '时', minutes + '分'].filter(v => !['0天', '0时', '0分'].includes(v))).join('')
item.bfTime = (72000 - item.remaining_time) / 72000 * 100 + '%'
if (item.avatars.length == 1) {
item.avatars.push('派遣头像')
}
2023-03-04 14:30:13 +08:00
}
// 标识属性图标~
2023-05-09 11:03:38 +08:00
let icon = lodash.sample(['希儿', '白露', '艾丝妲', '布洛妮娅', '姬子', '卡芙卡', '克拉拉', '停云', '佩拉', '黑塔', '希露瓦', '银狼'])
let week = [
2023-05-09 11:03:38 +08:00
'星期日',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六'
]
let day = `${week[moment().day()]}`
return {
uid: this.e.uid,
2023-05-09 11:03:38 +08:00
saveId: this.e.uid, icon, day,
resinMaxTime, nowDay: moment(new Date()).format('YYYY年MM月DD日'),
...data
}
2023-03-04 14:30:13 +08:00
}
2023-05-09 11:03:38 +08:00
noteData (res) {
let { data } = res
let nowDay = moment().date()
let nowUnix = Number(moment().format('X'))
2023-03-04 14:30:13 +08:00
/** 树脂 */
2023-05-09 11:03:38 +08:00
let resinMaxTime
2023-03-04 14:30:13 +08:00
if (data.resin_recovery_time > 0) {
2023-05-09 11:03:38 +08:00
resinMaxTime = nowUnix + Number(data.resin_recovery_time)
2023-03-04 14:30:13 +08:00
2023-05-09 11:03:38 +08:00
let maxDate = moment.unix(resinMaxTime)
resinMaxTime = maxDate.format('HH:mm')
2023-03-04 14:30:13 +08:00
if (maxDate.date() != nowDay) {
2023-05-09 11:03:38 +08:00
resinMaxTime = `明天 ${resinMaxTime}`
2023-03-04 14:30:13 +08:00
} else {
2023-05-09 11:03:38 +08:00
resinMaxTime = ` ${resinMaxTime}`
2023-03-04 14:30:13 +08:00
}
}
/** 派遣 */
2023-05-09 11:03:38 +08:00
let remainedTime = ''
2023-03-04 14:30:13 +08:00
if (data.expeditions && data.expeditions.length >= 1) {
2023-05-09 11:03:38 +08:00
remainedTime = lodash.map(data.expeditions, 'remained_time')
remainedTime = lodash.min(remainedTime)
2023-03-04 14:30:13 +08:00
if (remainedTime > 0) {
2023-05-09 11:03:38 +08:00
remainedTime = nowUnix + Number(remainedTime)
let remainedDate = moment.unix(remainedTime)
remainedTime = remainedDate.format('HH:mm')
2023-03-04 14:30:13 +08:00
if (remainedDate.date() != nowDay) {
2023-05-09 11:03:38 +08:00
remainedTime = `明天 ${remainedTime}`
2023-03-04 14:30:13 +08:00
} else {
2023-05-09 11:03:38 +08:00
remainedTime = ` ${remainedTime}`
2023-03-04 14:30:13 +08:00
}
}
}
/** 宝钱 */
2023-05-09 11:03:38 +08:00
let coinTime = ''
2023-03-04 14:30:13 +08:00
if (data.home_coin_recovery_time > 0) {
2023-05-09 11:03:38 +08:00
let coinDay = Math.floor(data.home_coin_recovery_time / 3600 / 24)
let coinHour = Math.floor((data.home_coin_recovery_time / 3600) % 24)
let coinMin = Math.floor((data.home_coin_recovery_time / 60) % 60)
2023-03-04 14:30:13 +08:00
if (coinDay > 0) {
2023-05-09 11:03:38 +08:00
coinTime = `${coinDay}${coinHour}小时${coinMin}分钟`
2023-03-04 14:30:13 +08:00
} else {
let coinDate = moment.unix(
nowUnix + Number(data.home_coin_recovery_time)
2023-05-09 11:03:38 +08:00
)
2023-03-04 14:30:13 +08:00
if (coinDate.date() != nowDay) {
2023-05-09 11:03:38 +08:00
coinTime = `明天 ${coinDate.format('HH:mm')}`
2023-03-04 14:30:13 +08:00
} else {
2023-05-09 11:03:38 +08:00
coinTime = coinDate.format('HH:mm')
2023-03-04 14:30:13 +08:00
}
}
}
let week = [
2023-05-09 11:03:38 +08:00
'星期日',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六'
]
let day = `${moment().format('MM-DD HH:mm')} ${week[moment().day()]}`
2023-03-04 14:30:13 +08:00
/** 参量质变仪 */
if (data?.transformer?.obtained) {
2023-05-09 11:03:38 +08:00
data.transformer.reached = data.transformer.recovery_time.reached
let recoveryTime = ''
2023-03-04 14:30:13 +08:00
if (data.transformer.recovery_time.Day > 0) {
2023-05-09 11:03:38 +08:00
recoveryTime += `${data.transformer.recovery_time.Day}`
2023-03-04 14:30:13 +08:00
}
if (data.transformer.recovery_time.Hour > 0) {
2023-05-09 11:03:38 +08:00
recoveryTime += `${data.transformer.recovery_time.Hour}小时`
2023-03-04 14:30:13 +08:00
}
if (data.transformer.recovery_time.Minute > 0) {
2023-05-09 11:03:38 +08:00
recoveryTime += `${data.transformer.recovery_time.Minute}分钟`
2023-03-04 14:30:13 +08:00
}
2023-05-09 11:03:38 +08:00
data.transformer.recovery_time = recoveryTime
2023-03-04 14:30:13 +08:00
}
return {
uid: this.e.uid,
saveId: this.e.uid,
resinMaxTime,
remainedTime,
coinTime,
day,
2023-05-09 11:03:38 +08:00
...data
}
2023-03-04 14:30:13 +08:00
}
}