Module.getDataの返値がundefinedになる可能性がある問題を修正

This commit is contained in:
takejohn 2024-03-30 20:04:49 +09:00
parent b2ab6778b0
commit 3f710c7c6b
2 changed files with 9 additions and 4 deletions

View file

@ -54,7 +54,6 @@ export default class 藍 {
private mentionHooks: MentionHook[] = []; private mentionHooks: MentionHook[] = [];
private contextHooks: { [moduleName: string]: ContextHook } = {}; private contextHooks: { [moduleName: string]: ContextHook } = {};
private timeoutCallbacks: { [moduleName: string]: TimeoutCallback } = {}; private timeoutCallbacks: { [moduleName: string]: TimeoutCallback } = {};
public installedModules: { [moduleName: string]: InstalledModule } = {};
public db: loki; public db: loki;
public lastSleepedAt: number; public lastSleepedAt: number;

View file

@ -75,10 +75,16 @@ export default abstract class Module {
*/ */
@bindThis @bindThis
protected getData() { protected getData() {
const doc = this.ai.moduleData.findOne({ let doc = this.ai.moduleData.findOne({
module: this.name 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<M extends Module = Module, Data = any> imp
this.doc = doc; this.doc = doc;
} }
ai.installedModules[module.name] = this; module.installed = this;
} }
@bindThis @bindThis