mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 05:08:00 +00:00
Module.getDataの返値がundefinedになる可能性がある問題を修正
This commit is contained in:
parent
b2ab6778b0
commit
3f710c7c6b
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue