runtime适配星铁

This commit is contained in:
Aluxes 2024-04-05 07:55:38 +08:00
parent 134d1cbb37
commit 61f513ac39
No known key found for this signature in database
GPG Key ID: 6696152F9C003087
2 changed files with 43 additions and 35 deletions

View File

@ -22,7 +22,7 @@ import Handler from './handler.js'
*/ */
export default class Runtime { export default class Runtime {
constructor (e) { constructor(e) {
this.e = e this.e = e
this._mysInfo = {} this._mysInfo = {}
@ -138,12 +138,13 @@ export default class Runtime {
* *
* @param targetType all: 所有用户均可 cookie查询用户必须具备Cookie * @param targetType all: 所有用户均可 cookie查询用户必须具备Cookie
* @param option MysApi option * @param option MysApi option
* @param isSr 是否为星穹铁道
* @returns {Promise<boolean|MysApi>} * @returns {Promise<boolean|MysApi>}
*/ */
async getMysApi (targetType = 'all', option = {}) { async getMysApi (targetType = 'all', option = {}, isSr = false) {
let mys = await this.getMysInfo(targetType) let mys = await this.getMysInfo(targetType)
if (mys.uid && mys?.ckInfo?.ck) { if (mys.uid && mys?.ckInfo?.ck) {
return new MysApi(mys.uid, mys.ckInfo.ck, option) return new MysApi(mys.uid, mys.ckInfo.ck, option, isSr)
} }
return false return false
} }
@ -153,10 +154,11 @@ export default class Runtime {
* @param uid * @param uid
* @param ck * @param ck
* @param option * @param option
* @param isSr 是否为星穹铁道
* @returns {Promise<MysApi>} * @returns {Promise<MysApi>}
*/ */
async createMysApi (uid, ck, option) { async createMysApi (uid, ck, option, isSr = false) {
return new MysApi(uid, ck, option) return new MysApi(uid, ck, option, isSr)
} }
/** /**

View File

@ -29,11 +29,11 @@ export default class MysInfo {
this.gtest = false this.gtest = false
this.mysButton = segment.button([ this.mysButton = segment.button([
{ text: "米游社", link: "https://miyoushe.com" }, { text: '米游社', link: 'https://miyoushe.com' }
]) ])
} }
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)
@ -80,7 +80,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) {
/** 没有绑定的自动绑定 */ /** 没有绑定的自动绑定 */
@ -96,9 +96,11 @@ export default class MysInfo {
let atUser = await NoteUser.create(at) let atUser = await NoteUser.create(at)
uid = atUser.getUid(e) uid = atUser.getUid(e)
if (uid) return String(uid) if (uid) return String(uid)
if (e.noTips !== true) e.reply(['尚未绑定uid', segment.button([ if (e.noTips !== true) {
{ text: "绑定UID", input: "#绑定uid" }, e.reply(['尚未绑定uid', segment.button([
])], false, { at }) { text: '绑定UID', input: '#绑定uid' }
])], false, { at })
}
return false return false
} }
@ -116,9 +118,11 @@ export default class MysInfo {
return user.autoRegUid(uid, e) return user.autoRegUid(uid, e)
} }
if (e.noTips !== true) e.reply(['请先#绑定uid', segment.button([ if (e.noTips !== true) {
{ text: "绑定UID", input: "#绑定uid" }, e.reply(['请先#绑定uid', segment.button([
])], false, { at: at || true }) { text: '绑定UID', input: '#绑定uid' }
])], false, { at: at || true })
}
return false return false
} }
@ -128,7 +132,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
@ -136,9 +140,11 @@ export default class MysInfo {
let selfUser = at ? await NoteUser.create(at) : user let selfUser = at ? await NoteUser.create(at) : user
if (!selfUser.hasCk) { if (!selfUser.hasCk) {
if (e.noTips !== true) e.reply(['尚未绑定Cookie', segment.button([ if (e.noTips !== true) {
{ text: "Cookie帮助", callback: "#Cookie帮助" }, e.reply(['尚未绑定Cookie', segment.button([
])], false, { at: selfUser.qq }) { text: 'Cookie帮助', callback: '#Cookie帮助' }
])], false, { at: selfUser.qq })
}
return false return false
} }
@ -163,7 +169,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
@ -209,7 +215,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') || []
@ -233,7 +239,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) => {
@ -251,7 +257,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')) {
@ -274,13 +280,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
@ -288,12 +294,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
} }
@ -309,18 +315,18 @@ 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) {
this.e.reply(['请先#绑定uid', segment.button([ this.e.reply(['请先#绑定uid', segment.button([
{ text: "绑定UID", input: "#绑定uid" }, { text: '绑定UID', input: '#绑定uid' }
])], false, { at: true }) ])], false, { at: true })
} }
if (!this.ckInfo.ck) { if (!this.ckInfo.ck) {
this.e.reply(['暂无可用CK请绑定更多用户或设置公共ck..', segment.button([ this.e.reply(['暂无可用CK请绑定更多用户或设置公共ck..', segment.button([
{ text: "Cookie帮助", callback: "#Cookie帮助" }, { text: 'Cookie帮助', callback: '#Cookie帮助' }
])]) ])])
} }
@ -334,13 +340,13 @@ 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)
if (mysUser) { if (mysUser) {
if (mysUser.ck) { if (mysUser.ck) {
this.ckInfo = mysUser.getCkInfo() this.ckInfo = mysUser.getCkInfo(game)
this.ckUser = mysUser this.ckUser = mysUser
// 暂时直接记录请求uid后期优化分析MysApi请求结果分状态记录结果 // 暂时直接记录请求uid后期优化分析MysApi请求结果分状态记录结果
await mysUser.addQueryUid(this.uid, game) await mysUser.addQueryUid(this.uid, game)
@ -353,7 +359,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([`UID:${this.uid},米游社接口请求失败,暂时无法查询`, this.mysButton]) if (!isTask) this.e.reply([`UID:${this.uid},米游社接口请求失败,暂时无法查询`, this.mysButton])
return false return false
@ -442,7 +448,7 @@ export default class MysInfo {
} }
/** 删除失效ck */ /** 删除失效ck */
async delCk() { async delCk () {
if (!this.ckUser) { if (!this.ckUser) {
return false return false
} }
@ -452,8 +458,8 @@ export default class MysInfo {
} }
/** 查询次数满,今日内标记失效 */ /** 查询次数满,今日内标记失效 */
async disableToday(game = 'gs') { async disableToday (game = 'gs') {
/** 统计次数设为超限 */ /** 统计次数设为超限 */
await this.ckUser.disable(game) await this.ckUser.disable(game)
} }
} }