From 4972afc16a875b03db67a587e3d59228f8242a9c Mon Sep 17 00:00:00 2001 From: snowy Date: Fri, 8 Mar 2024 20:11:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=90=8E=E4=B8=8D=E6=8E=A8=E9=80=81`ConnectMetaEvent`=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- onebot_event.go | 11 ++++++++++- proto_event.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/onebot_event.go b/onebot_event.go index df24194..6455b29 100644 --- a/onebot_event.go +++ b/onebot_event.go @@ -41,7 +41,16 @@ type marshaledEvent struct { } func (ob *OneBot) openEventListenChan() <-chan marshaledEvent { - ch := make(chan marshaledEvent) // TODO: channel size + ch := make(chan marshaledEvent, 1) + connectMetaEvent := MakeConnectMetaEvent(ob.Impl, Version, OneBotVersion) + ob.Logger.Debugf("事件: %#v", connectMetaEvent) + ob.Logger.Infof("事件 `%v` 开始推送", connectMetaEvent.Name()) + eventBytes, _ := json.Marshal(connectMetaEvent) + ch <- marshaledEvent{ + name: connectMetaEvent.Name(), + bytes: eventBytes, + raw: &connectMetaEvent, + } ob.eventListenChansLock.Lock() ob.eventListenChans = append(ob.eventListenChans, ch) ob.eventListenChansLock.Unlock() diff --git a/proto_event.go b/proto_event.go index 7d2cf9f..484670b 100644 --- a/proto_event.go +++ b/proto_event.go @@ -92,6 +92,21 @@ func MakeMetaEvent(time time.Time, detailType string) MetaEvent { } } +type VersionStruct struct { + Impl string `json:"impl"` + Version string `json:"version"` + OnebotVersion string `json:"onebot_version"` +} + +type ConnectMetaEvent struct { + MetaEvent + Version VersionStruct `json:"version"` +} + +func MakeConnectMetaEvent(impl, v, onebotVersion string) ConnectMetaEvent { + return ConnectMetaEvent{MetaEvent: MakeMetaEvent(time.Now(), "connect"), Version: VersionStruct{impl, v, onebotVersion}} +} + // MessageEvent 表示一个消息事件. type MessageEvent struct { Event