From abc0e5b095faac8dd72bbc11247e6e1fdd48129f Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Mon, 22 Feb 2016 00:11:39 -0800 Subject: [PATCH 1/3] Work around a Discord server issue. --- structs.go | 17 +++++++++-------- wsapi.go | 7 +++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/structs.go b/structs.go index 70c4844..2b57062 100644 --- a/structs.go +++ b/structs.go @@ -170,13 +170,14 @@ type Guild struct { // A Role stores information about Discord guild member roles. type Role struct { - ID string `json:"id"` - Name string `json:"name"` - Managed bool `json:"managed"` - Hoist bool `json:"hoist"` - Color int `json:"color"` - Position int `json:"position"` - Permissions int `json:"permissions"` + ID string `json:"id"` + Name string `json:"name"` + Managed bool `json:"managed"` + Hoist bool `json:"hoist"` + // This is coming back as an int or string, for now do not parse. + Color int `json:"-"` + Position int `json:"position"` + Permissions int `json:"permissions"` } // A VoiceState stores the voice states of Guilds @@ -274,7 +275,7 @@ type RateLimit struct { // A ReadState stores data on the read state of channels. type ReadState struct { - MentionCount int + MentionCount int `json:"mention_count"` LastMessageID string `json:"last_message_id"` ID string `json:"id"` } diff --git a/wsapi.go b/wsapi.go index 2337916..7e4ad19 100644 --- a/wsapi.go +++ b/wsapi.go @@ -284,8 +284,11 @@ func (s *Session) event(messageType int, message []byte) { // Attempt to unmarshal our event. // If there is an error we should handle the event itself. if err = unmarshal(e.RawData, i); err != nil { - fmt.Println("Unable to unmarshal event data.") - i = e + fmt.Println("Unable to unmarshal event data.", err) + // Ready events must fire, even if they are empty. + if e.Type != "READY" { + i = e + } } } else { fmt.Println("Unknown event.") From 75a5d6bf629f130c474f9b1e38d8522e100105b7 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Mon, 22 Feb 2016 08:20:36 -0800 Subject: [PATCH 2/3] Bring back color --- structs.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/structs.go b/structs.go index 2b57062..c3f267d 100644 --- a/structs.go +++ b/structs.go @@ -170,14 +170,13 @@ type Guild struct { // A Role stores information about Discord guild member roles. type Role struct { - ID string `json:"id"` - Name string `json:"name"` - Managed bool `json:"managed"` - Hoist bool `json:"hoist"` - // This is coming back as an int or string, for now do not parse. - Color int `json:"-"` - Position int `json:"position"` - Permissions int `json:"permissions"` + ID string `json:"id"` + Name string `json:"name"` + Managed bool `json:"managed"` + Hoist bool `json:"hoist"` + Color int `json:"color"` + Position int `json:"position"` + Permissions int `json:"permissions"` } // A VoiceState stores the voice states of Guilds From a11e81fc9642b4b2201838f6d4c9fa286236ffc7 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Mon, 22 Feb 2016 08:27:17 -0800 Subject: [PATCH 3/3] Bring back discrim too. --- structs.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/structs.go b/structs.go index c3f267d..f364fa4 100644 --- a/structs.go +++ b/structs.go @@ -215,24 +215,14 @@ type Member struct { // A User stores all data for an individual Discord user. type User struct { - ID string `json:"id"` - Email string `json:"email"` - Username string `json:"username"` - Avatar string `json:"Avatar"` - Verified bool `json:"verified"` - //Discriminator int `json:"discriminator,string"` // TODO: See below + ID string `json:"id"` + Email string `json:"email"` + Username string `json:"username"` + Avatar string `json:"Avatar"` + Verified bool `json:"verified"` + 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. type Settings struct { RenderEmbeds bool `json:"render_embeds"`