From 3f710c7c6b14f74deab735c1320579af8a6b3586 Mon Sep 17 00:00:00 2001 From: takejohn <105504345+takejohn@users.noreply.github.com> Date: Sat, 30 Mar 2024 20:04:49 +0900 Subject: [PATCH] =?UTF-8?q?Module.getData=E3=81=AE=E8=BF=94=E5=80=A4?= =?UTF-8?q?=E3=81=8Cundefined=E3=81=AB=E3=81=AA=E3=82=8B=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E6=80=A7=E3=81=8C=E3=81=82=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ai.ts | 1 - src/module.ts | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ai.ts b/src/ai.ts index 5d7476f..5bffc4d 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -54,7 +54,6 @@ export default class 藍 { private mentionHooks: MentionHook[] = []; private contextHooks: { [moduleName: string]: ContextHook } = {}; private timeoutCallbacks: { [moduleName: string]: TimeoutCallback } = {}; - public installedModules: { [moduleName: string]: InstalledModule } = {}; public db: loki; public lastSleepedAt: number; diff --git a/src/module.ts b/src/module.ts index ce271f9..6684e91 100644 --- a/src/module.ts +++ b/src/module.ts @@ -75,10 +75,16 @@ export default abstract class Module { */ @bindThis protected getData() { - const doc = this.ai.moduleData.findOne({ + let doc = this.ai.moduleData.findOne({ module: this.name }); - return doc?.data; + if (doc == null) { + doc = this.ai.moduleData.insertOne({ + module: this.name, + data: {} + }); + } + return doc.data; } /** @@ -124,7 +130,7 @@ export abstract class InstalledModule imp this.doc = doc; } - ai.installedModules[module.name] = this; + module.installed = this; } @bindThis