mirror of
https://github.com/PHIDIAS0303/ClusterChatSync.git
synced 2026-11-24 00:13:12 +09:00
Enhance ChatEvent with JSON schema and fromJSON method
Added JSON schema validation and deserialization to ChatEvent.
This commit is contained in:
1 parent
6ad2d7ac5e
commit
0bef499aac
1 file changed
+8
-6
@@ -16,13 +16,15 @@ export class ChatEvent {
|
|||||||
public content: string,
|
public content: string,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
static async fromContext(context: InstancePluginContext) {
|
static jsonSchema = Type.Object({
|
||||||
return new ChatEvent(context.instance, context.action, context.content);
|
'instance': Type.Any(),
|
||||||
}
|
'action': Type.String(),
|
||||||
}
|
'content': Type.String(),
|
||||||
|
});
|
||||||
|
|
||||||
export default async function (context: InstancePluginContext) {
|
static fromJSON(json: Static<typeof ChatEvent.jsonSchema>) {
|
||||||
await ChatEvent.fromContext(context);
|
return new this(json.instance, json.action, json.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@clusterio/lib' {
|
declare module '@clusterio/lib' {
|
||||||
|
|||||||
Reference in new issue
Block a user