Miao-Yunzai/plugins/genshin/model/mys/MysUtil.js

50 lines
1006 B
JavaScript

import { Data } from '#miao'
const games = ['gs', 'sr']
const MysUtil = {
// 获取标准ltuid
getLtuid (data) {
if (!data) {
return false
}
if (/^\d{4,9}$/.test(data)) {
return data
}
let testRet = /ltuid=(\d{4,9})/g.exec(data.ck || data)
if (testRet && testRet[1]) {
return testRet[1]
}
return false
},
// 获取标准gameKey
getGameKey (game) {
// 兼容e的处理
if (game.user_id) {
return game.isSr ? 'sr' : 'gs'
}
return ['sr', 'star'].includes(game) ? 'sr' : 'gs'
},
// 生成设备guid
getDeviceGuid () {
function S4 () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
},
// 循环game
async eachGame (fn) {
await Data.forEach(games, fn)
},
// 循环server
async eachServ (fn) {
await Data.forEach(['mys', 'hoyolab'], fn)
}
}
export default MysUtil