Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not push ConnectMetaEvent after connection #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion onebot_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions proto_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down