Merge pull request #131 from iopred/docs
Allow Ready events to fire even after a unmarshalling error.
This commit is contained in:
commit
ec5dd888c1
2 changed files with 12 additions and 19 deletions
24
structs.go
24
structs.go
|
@ -215,24 +215,14 @@ type Member struct {
|
||||||
|
|
||||||
// A User stores all data for an individual Discord user.
|
// A User stores all data for an individual Discord user.
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Avatar string `json:"Avatar"`
|
Avatar string `json:"Avatar"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
//Discriminator int `json:"discriminator,string"` // TODO: See below
|
Discriminator string `json:"discriminator"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Research issue.
|
|
||||||
// Discriminator sometimes comes as a string
|
|
||||||
// and sometimes it comes as a int. Weird.
|
|
||||||
// to avoid errors I've just commented it out
|
|
||||||
// but it doesn't seem to just kill the whole
|
|
||||||
// program. Heartbeat is taken on READY even
|
|
||||||
// with error and the system continues to read
|
|
||||||
// it just doesn't seem able to handle this one
|
|
||||||
// field correctly. Need to research this more.
|
|
||||||
|
|
||||||
// A Settings stores data for a specific users Discord client settings.
|
// A Settings stores data for a specific users Discord client settings.
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
RenderEmbeds bool `json:"render_embeds"`
|
RenderEmbeds bool `json:"render_embeds"`
|
||||||
|
@ -274,7 +264,7 @@ type RateLimit struct {
|
||||||
|
|
||||||
// A ReadState stores data on the read state of channels.
|
// A ReadState stores data on the read state of channels.
|
||||||
type ReadState struct {
|
type ReadState struct {
|
||||||
MentionCount int
|
MentionCount int `json:"mention_count"`
|
||||||
LastMessageID string `json:"last_message_id"`
|
LastMessageID string `json:"last_message_id"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
7
wsapi.go
7
wsapi.go
|
@ -284,8 +284,11 @@ func (s *Session) event(messageType int, message []byte) {
|
||||||
// Attempt to unmarshal our event.
|
// Attempt to unmarshal our event.
|
||||||
// If there is an error we should handle the event itself.
|
// If there is an error we should handle the event itself.
|
||||||
if err = unmarshal(e.RawData, i); err != nil {
|
if err = unmarshal(e.RawData, i); err != nil {
|
||||||
fmt.Println("Unable to unmarshal event data.")
|
fmt.Println("Unable to unmarshal event data.", err)
|
||||||
i = e
|
// Ready events must fire, even if they are empty.
|
||||||
|
if e.Type != "READY" {
|
||||||
|
i = e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Unknown event.")
|
fmt.Println("Unknown event.")
|
||||||
|
|
Loading…
Reference in a new issue