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