mirror of
https://github.com/PHIDIAS0303/ClusterChatSync.git
synced 2026-11-11 15:14:52 +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,
|
||||
) {}
|
||||
|
||||
static async fromContext(context: InstancePluginContext) {
|
||||
return new ChatEvent(context.instance, context.action, context.content);
|
||||
}
|
||||
}
|
||||
static jsonSchema = Type.Object({
|
||||
'instance': Type.Any(),
|
||||
'action': Type.String(),
|
||||
'content': Type.String(),
|
||||
});
|
||||
|
||||
export default async function (context: InstancePluginContext) {
|
||||
await ChatEvent.fromContext(context);
|
||||
static fromJSON(json: Static<typeof ChatEvent.jsonSchema>) {
|
||||
return new this(json.instance, json.action, json.content);
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@clusterio/lib' {
|
||||
|
||||
Reference in new issue
Block a user