From e8725f5d3da2f1516dc8c97823a9ff6736ffd95d Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Thu, 1 Jun 2023 04:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4runtime.user=EF=BC=8C?= =?UTF-8?q?=E6=9A=B4=E9=9C=B2=E7=94=A8=E6=88=B7=E7=9B=B8=E5=85=B3=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E4=B8=8E=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/runtime.js | 44 +++++++++++++++++++++++++-- plugins/genshin/model/mys/NoteUser.js | 23 ++++++++------ plugins/genshin/model/mys/mysInfo.js | 10 ------ 3 files changed, 54 insertions(+), 23 deletions(-) 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