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

Mapped Event Handlers #109

Merged
merged 5 commits into from
Feb 16, 2016
Merged

Mapped Event Handlers #109

merged 5 commits into from
Feb 16, 2016

Conversation

iopred
Copy link
Collaborator

@iopred iopred commented Feb 15, 2016

This change breaks the current API but makes it much more powerful.

Currently only one handler can be added for each event, with this change, any number of handlers can be added for the same event. Additionally it supports adding handlers for interface{} which will be triggered on every event.

The existing code:

dg.OnMessageCreate = func(s *discordgo.Session, m *discordgo.Message){
  fmt.Println(m.Content)
}

is now:

dg.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate){
  fmt.Println(m.Content)
})

Not bad for a net delta of -:100: lines.

@iopred iopred mentioned this pull request Feb 15, 2016
}
// Attempt to unmarshal our event.
// If there is an error we should handle the event itself.
if err = unmarshal(e.RawData, i); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We unmarshal every event now.

It's a small change, and doesn't really change the runtime performance that I can see, but it is required to support the interface{} event type, which is really handy 👌


// Exposed but should not be modified by User.
SessionID string // from websocket READY packet
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed SessionID as it is accessible from State.SessionID.

@bwmarrin bwmarrin added the feature Major feature implementation label Feb 16, 2016
@bwmarrin bwmarrin added this to the v0.11.0 milestone Feb 16, 2016
bwmarrin added a commit that referenced this pull request Feb 16, 2016
BREAKING CHANGE -- Mapped Event Handlers
@bwmarrin bwmarrin merged commit 28236b4 into bwmarrin:develop Feb 16, 2016
@iopred iopred deleted the map branch February 16, 2016 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Major feature implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants