diff --git a/lib/plugins/runtime.js b/lib/plugins/runtime.js index b6ecdc2..8c4c7cf 100644 --- a/lib/plugins/runtime.js +++ b/lib/plugins/runtime.js @@ -67,9 +67,47 @@ export default class Runtime { } static async init (e) { - e.runtime = new Runtime(e) - e.user = await MysInfo.getNoteUser(e) - return e.runtime + await MysInfo.initCache() + let runtime = new Runtime(e) + e.runtime = runtime + e.game = e.isSr ? 'sr' : 'gs' + await runtime.initUser() + return runtime + } + + async initUser () { + let e = this.e + let user = await NoteUser.create(e) + if (user) { + e.user = new Proxy(user, { + get (self, key, receiver) { + let game = e.isSr ? 'sr' : 'gs' + let fnMap = { + uid: 'getUid', + uidList: 'getUidList', + mysUser: 'getMysUser', + ckUidList: 'getCkUidList' + } + if (fnMap[key]) { + return self[fnMap[key]](game) + } + if (key === 'uidData') { + return self.getUidData('', game) + } + if (['getUid', 'getUidList', 'getMysUser', 'getCkUidList', 'getUidMapList', 'getGameDs'].includes(key)) { + return (_game, arg2) => { + return self[key](_game || game, arg2) + } + } + if (['getUidData', 'hasUid', 'addRegUid', 'delRegUid', 'setMainUid'].includes(key)) { + return (uid, _game = '') => { + return self[key](uid, _game || game) + } + } + return self[key] + } + }) + } } /** diff --git a/plugins/genshin/model/mys/NoteUser.js b/plugins/genshin/model/mys/NoteUser.js index e601271..2453dd5 100644 --- a/plugins/genshin/model/mys/NoteUser.js +++ b/plugins/genshin/model/mys/NoteUser.js @@ -286,16 +286,6 @@ export default class NoteUser extends BaseModel { this.save() } - /** - * 获取当前用户的绑定UID - * 主要供内部调用,建议使用 user.uid 获取用户uid - * @returns {Promise<*>} - */ - async getRegUid (game = 'gs') { - let gameDs = this.getGameDs(game) - return gameDs.uid || '' - } - getGameDs (game = 'gs') { return this.games[this.gameKey(game)] } @@ -359,6 +349,19 @@ export default class NoteUser extends BaseModel { await this.save() } + async eachMysUser (fn) { + await Data.forEach(this.mysUsers, async (mys, ltuid) => { + if (!mys) { + return true + } + return fn(mys, ltuid) + }) + } + + async eachAllMysUser (fn) { + return MysUser.forEach(fn) + } + /** * 检查当前用户绑定的CK状态 */ diff --git a/plugins/genshin/model/mys/mysInfo.js b/plugins/genshin/model/mys/mysInfo.js index 5f8735b..a63dce9 100644 --- a/plugins/genshin/model/mys/mysInfo.js +++ b/plugins/genshin/model/mys/mysInfo.js @@ -66,19 +66,9 @@ export default class MysInfo { /** 判断回复 */ await mysInfo.checkReply() - return mysInfo } - static async getNoteUser (e) { - await MysInfo.initCache() - let user = await NoteUser.create(e) - if (user) { - return user - } - return false - } - /** * 获取UID * @param e