Miao-Yunzai/src/mys/MysUtil.ts

68 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-06-09 01:00:07 +08:00
import { Data } from './local.js'
2024-06-09 01:00:25 +08:00
const games = [
{ key: 'gs', name: '原神' },
{ key: 'sr', name: '星穹铁道' }
]
2024-06-09 01:00:07 +08:00
const MysUtil = {
// 获取标准ltuid
2024-06-09 01:00:25 +08:00
getLtuid(data) {
2024-06-09 01:00:07 +08:00
if (!data) {
return false
}
if (/^\d{4,10}$/.test(data)) {
return data
}
let testRet = /ltuid=(\d{4,10})/g.exec(data.ck || data)
if (testRet && testRet[1]) {
return testRet[1]
}
return false
},
// 获取标准gameKey
2024-06-09 01:00:25 +08:00
getGameKey(game) {
2024-06-09 01:00:07 +08:00
// 兼容e的处理
if (game.user_id) {
return game.isSr ? 'sr' : 'gs'
}
return ['sr', 'star'].includes(game) ? 'sr' : 'gs'
},
// 生成设备guid
2024-06-09 01:00:25 +08:00
getDeviceGuid() {
function S4() {
2024-06-09 01:00:07 +08:00
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
}
2024-06-09 01:00:25 +08:00
return (
S4() +
S4() +
'-' +
S4() +
'-' +
S4() +
'-' +
S4() +
'-' +
S4() +
S4() +
S4()
)
2024-06-09 01:00:07 +08:00
},
// 循环game
2024-06-09 01:00:25 +08:00
async eachGame(fn) {
await Data.forEach(games, ds => {
2024-06-09 01:00:07 +08:00
return fn(ds.key, ds)
})
},
// 循环server
2024-06-09 01:00:25 +08:00
async eachServ(fn) {
2024-06-09 01:00:07 +08:00
await Data.forEach(['mys', 'hoyolab'], fn)
}
}
export default MysUtil