Compare commits

...

2 commits

Author SHA1 Message Date
Take-John 7fe378ca50
Merge 3f710c7c6b into 830c9c2ecd 2024-03-30 20:08:26 +09:00
takejohn 3f710c7c6b Module.getDataの返値がundefinedになる可能性がある問題を修正 2024-03-30 20:04:49 +09:00
2 changed files with 9 additions and 4 deletions

View file

@ -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;

View file

@ -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<M extends Module = Module, Data = any> imp
this.doc = doc;
}
ai.installedModules[module.name] = this;
module.installed = this;
}
@bindThis