Browse Source

Merge branch 'develop' of https://github.com/bwmarrin/Discordgo into develop

Bruce Marriner 9 years ago
parent
commit
73c0b90f16
3 changed files with 62 additions and 46 deletions
  1. 33 27
      events.go
  2. 24 17
      structs.go
  3. 5 2
      wsapi.go

+ 33 - 27
events.go

@@ -13,33 +13,34 @@ package discordgo
 //     Session.AddHandler(func(s *discordgo.Session, m *discordgo.PresenceUpdate) {
 //     })
 var eventToInterface = map[string]interface{}{
-	"CHANNEL_CREATE":            ChannelCreate{},
-	"CHANNEL_UPDATE":            ChannelUpdate{},
-	"CHANNEL_DELETE":            ChannelDelete{},
-	"GUILD_CREATE":              GuildCreate{},
-	"GUILD_UPDATE":              GuildUpdate{},
-	"GUILD_DELETE":              GuildDelete{},
-	"GUILD_BAN_ADD":             GuildBanAdd{},
-	"GUILD_BAN_REMOVE":          GuildBanRemove{},
-	"GUILD_MEMBER_ADD":          GuildMemberAdd{},
-	"GUILD_MEMBER_UPDATE":       GuildMemberUpdate{},
-	"GUILD_MEMBER_REMOVE":       GuildMemberRemove{},
-	"GUILD_ROLE_CREATE":         GuildRoleCreate{},
-	"GUILD_ROLE_UPDATE":         GuildRoleUpdate{},
-	"GUILD_ROLE_DELETE":         GuildRoleDelete{},
-	"GUILD_INTEGRATIONS_UPDATE": GuildIntegrationsUpdate{},
-	"GUILD_EMOJIS_UPDATE":       GuildEmojisUpdate{},
-	"MESSAGE_ACK":               MessageAck{},
-	"MESSAGE_CREATE":            MessageCreate{},
-	"MESSAGE_UPDATE":            MessageUpdate{},
-	"MESSAGE_DELETE":            MessageDelete{},
-	"PRESENCE_UPDATE":           PresenceUpdate{},
-	"READY":                     Ready{},
-	"USER_UPDATE":               UserUpdate{},
-	"USER_SETTINGS_UPDATE":      UserSettingsUpdate{},
-	"TYPING_START":              TypingStart{},
-	"VOICE_SERVER_UPDATE":       VoiceServerUpdate{},
-	"VOICE_STATE_UPDATE":        VoiceStateUpdate{},
+	"CHANNEL_CREATE":             ChannelCreate{},
+	"CHANNEL_UPDATE":             ChannelUpdate{},
+	"CHANNEL_DELETE":             ChannelDelete{},
+	"GUILD_CREATE":               GuildCreate{},
+	"GUILD_UPDATE":               GuildUpdate{},
+	"GUILD_DELETE":               GuildDelete{},
+	"GUILD_BAN_ADD":              GuildBanAdd{},
+	"GUILD_BAN_REMOVE":           GuildBanRemove{},
+	"GUILD_MEMBER_ADD":           GuildMemberAdd{},
+	"GUILD_MEMBER_UPDATE":        GuildMemberUpdate{},
+	"GUILD_MEMBER_REMOVE":        GuildMemberRemove{},
+	"GUILD_ROLE_CREATE":          GuildRoleCreate{},
+	"GUILD_ROLE_UPDATE":          GuildRoleUpdate{},
+	"GUILD_ROLE_DELETE":          GuildRoleDelete{},
+	"GUILD_INTEGRATIONS_UPDATE":  GuildIntegrationsUpdate{},
+	"GUILD_EMOJIS_UPDATE":        GuildEmojisUpdate{},
+	"MESSAGE_ACK":                MessageAck{},
+	"MESSAGE_CREATE":             MessageCreate{},
+	"MESSAGE_UPDATE":             MessageUpdate{},
+	"MESSAGE_DELETE":             MessageDelete{},
+	"PRESENCE_UPDATE":            PresenceUpdate{},
+	"READY":                      Ready{},
+	"USER_UPDATE":                UserUpdate{},
+	"USER_SETTINGS_UPDATE":       UserSettingsUpdate{},
+	"USER_GUILD_SETTINGS_UPDATE": UserGuildSettingsUpdate{},
+	"TYPING_START":               TypingStart{},
+	"VOICE_SERVER_UPDATE":        VoiceServerUpdate{},
+	"VOICE_STATE_UPDATE":         VoiceStateUpdate{},
 }
 
 // Connect is an empty struct for an event.
@@ -140,3 +141,8 @@ type UserUpdate struct {
 
 // UserSettingsUpdate is a map for an event.
 type UserSettingsUpdate map[string]interface{}
+
+// UserGuildSettingsUpdate is a map for an event.
+type UserGuildSettingsUpdate struct {
+	*UserGuildSettings
+}

+ 24 - 17
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"`
@@ -274,7 +264,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"`
 }
@@ -331,6 +321,23 @@ type GuildEmojisUpdate struct {
 	Emojis  []*Emoji `json:"emojis"`
 }
 
+// A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
+type UserGuildSettingsChannelOverride struct {
+	Muted                bool   `json:"muted"`
+	MessageNotifications int    `json:"message_notifications"`
+	ChannelID            string `json:"channel_id"`
+}
+
+// A UserGuildSettings stores data for a users guild settings.
+type UserGuildSettings struct {
+	SupressEveryone      bool                                `json:"suppress_everyone"`
+	Muted                bool                                `json:"muted"`
+	MobilePush           bool                                `json:"mobile_push"`
+	MessageNotifications int                                 `json:"message_notifications"`
+	GuildID              string                              `json:"guild_id"`
+	ChannelOverrides     []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
+}
+
 // A State contains the current known state.
 // As discord sends this in a READY blob, it seems reasonable to simply
 // use that struct as the data store.

+ 5 - 2
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.")