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

make Gateway.Open wait until ready event is received #321

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
actually handle the resumed event
  • Loading branch information
topi314 committed Oct 10, 2023
commit 68bdea0b0053f08f9a4a70f6146a7199aa958e6c
6 changes: 6 additions & 0 deletions gateway/gateway_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 43,12 @@ type EventReady struct {
func (EventReady) messageData() {}
func (EventReady) eventData() {}

// EventResumed is the event sent by discord when you successfully resume
type EventResumed struct{}

func (EventResumed) messageData() {}
func (EventResumed) eventData() {}

type EventApplicationCommandPermissionsUpdate struct {
discord.ApplicationCommandPermissions
}
Expand Down
12 changes: 6 additions & 6 deletions gateway/gateway_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 424,6 @@ loop:
return
}

case OpcodeResume:
g.config.Logger.Debug(g.formatLogs("resume successful"))
g.status = StatusReady
readyChan <- nil
close(readyChan)

case OpcodeDispatch:
// set last sequence received
g.config.LastSequenceReceived = &message.S
Expand Down Expand Up @@ -462,6 456,12 @@ loop:
}
g.eventHandlerFunc(message.T, message.S, g.config.ShardID, eventData)
if _, ok = eventData.(EventReady); ok {
g.config.Logger.Debug(g.formatLogs("ready successful"))
readyChan <- nil
close(readyChan)
} else if _, ok = eventData.(EventResumed); ok {
g.config.Logger.Debug(g.formatLogs("resume successful"))
g.status = StatusReady
readyChan <- nil
close(readyChan)
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/gateway_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 112,7 @@ func UnmarshalEventData(data []byte, eventType EventType) (EventData, error) {
eventData = d

case EventTypeResumed:
// no data
eventData = EventResumed{}

case EventTypeApplicationCommandPermissionsUpdate:
var d EventApplicationCommandPermissionsUpdate
Expand Down