From 2a3be18e8dfaf75fbc46b227addb73b6d8e8f332 Mon Sep 17 00:00:00 2001 From: Shigma Date: Mon, 25 Nov 2024 14:12:28 +0800 Subject: [PATCH] fix(satori): ensure message.content in json format --- packages/core/src/session.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index c0e0cdac..bd19bc55 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -1,5 +1,5 @@ import { Channel, Event, GuildMember, Login, Message, User } from '@satorijs/protocol' -import { defineProperty, isNullable } from 'cosmokit' +import { clone, defineProperty, isNullable } from 'cosmokit' import { Context, Service } from 'cordis' import { Bot } from './bot' import h from '@satorijs/element' @@ -138,15 +138,20 @@ export class Session { }, this) } - toJSON(): Event { - return { + toJSON() { + const event: Event = { login: { platform: this.platform, user: { id: this.selfId }, } as Login, - ...this.event, + ...clone(this.event), id: this.id, } + if (event.message?.elements) { + event.message.content = this.content + delete event.message.elements + } + return event } }