From 918ee4205dcd5bd63977943145ca4e9e3d4e7ac0 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sun, 10 Jan 2016 21:20:19 -0800 Subject: [PATCH 1/4] Make User commands accessible only to @me --- restapi.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/restapi.go b/restapi.go index 46519a1..71fa6b2 100644 --- a/restapi.go +++ b/restapi.go @@ -180,8 +180,7 @@ func (s *Session) User(userID string) (st *User, err error) { } // UserUpdate updates a users settings. -// userID : A user ID or "@me" which is a shortcut of current user ID -func (s *Session) UserUpdate(userID, email, password, username, avatar, newPassword string) (st *User, err error) { +func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) { // NOTE: Avatar must be either the hash/id of existing Avatar or // data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG @@ -196,7 +195,7 @@ func (s *Session) UserUpdate(userID, email, password, username, avatar, newPassw NewPassword string `json:"new_password,omitempty"` }{email, password, username, avatar, newPassword} - body, err := s.Request("PATCH", USER(userID), data) + body, err := s.Request("PATCH", USER("@me"), data) err = json.Unmarshal(body, &st) return } @@ -218,45 +217,37 @@ func (s *Session) UserAvatar(userID string) (img image.Image, err error) { } // UserSettings returns the settings for a given user -// userID : A user ID or "@me" which is a shortcut of current user ID -// This seems to only return a result for "@me" func (s *Session) UserSettings(userID string) (st *Settings, err error) { - body, err := s.Request("GET", USER_SETTINGS(userID), nil) + body, err := s.Request("GET", USER_SETTINGS("@me"), nil) err = json.Unmarshal(body, &st) return } // UserChannels returns an array of Channel structures for all private -// channels for a user -// userID : A user ID or "@me" which is a shortcut of current user ID -func (s *Session) UserChannels(userID string) (st []*Channel, err error) { +// channels. +func (s *Session) UserChannels() (st []*Channel, err error) { - body, err := s.Request("GET", USER_CHANNELS(userID), nil) + body, err := s.Request("GET", USER_CHANNELS("@me"), nil) err = json.Unmarshal(body, &st) return } // UserChannelCreate creates a new User (Private) Channel with another User -// userID : A user ID or "@me" which is a shortcut of current user ID // recipientID : A user ID for the user to which this channel is opened with. -func (s *Session) UserChannelCreate(userID, recipientID string) (st *Channel, err error) { +func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) { data := struct { RecipientID string `json:"recipient_id"` }{recipientID} - body, err := s.Request( - "POST", - USER_CHANNELS(userID), - data) + body, err := s.Request("POST", USER_CHANNELS("@me"), data) err = json.Unmarshal(body, &st) return } -// UserGuilds returns an array of Guild structures for all guilds for a given user -// userID : A user ID or "@me" which is a shortcut of current user ID +// UserGuilds returns an array of Guild structures for all guilds. func (s *Session) UserGuilds(userID string) (st []*Guild, err error) { body, err := s.Request("GET", USER_GUILDS(userID), nil) From d52e39a592158436faa7a0afe9b66cbb0f2f7325 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sun, 10 Jan 2016 21:23:15 -0800 Subject: [PATCH 2/4] Move non @me methods higher, modify UserGuilds. --- restapi.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/restapi.go b/restapi.go index 71fa6b2..e7f64d6 100644 --- a/restapi.go +++ b/restapi.go @@ -179,6 +179,22 @@ func (s *Session) User(userID string) (st *User, err error) { return } +// UserAvatar returns an image.Image of a users Avatar +// userID : A user ID or "@me" which is a shortcut of current user ID +func (s *Session) UserAvatar(userID string) (img image.Image, err error) { + u, err := s.User(userID) + if err != nil { + return + } + body, err := s.Request("GET", USER_AVATAR(userID, u.Avatar), nil) + if err != nil { + return nil, err + } + + img, _, err = image.Decode(bytes.NewReader(body)) + return +} + // UserUpdate updates a users settings. func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error) { @@ -200,22 +216,6 @@ func (s *Session) UserUpdate(email, password, username, avatar, newPassword stri return } -// UserAvatar returns an image.Image of a users Avatar -// userID : A user ID or "@me" which is a shortcut of current user ID -func (s *Session) UserAvatar(userID string) (img image.Image, err error) { - u, err := s.User(userID) - if err != nil { - return - } - body, err := s.Request("GET", USER_AVATAR(userID, u.Avatar), nil) - if err != nil { - return nil, err - } - - img, _, err = image.Decode(bytes.NewReader(body)) - return -} - // UserSettings returns the settings for a given user func (s *Session) UserSettings(userID string) (st *Settings, err error) { @@ -248,9 +248,9 @@ func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) } // UserGuilds returns an array of Guild structures for all guilds. -func (s *Session) UserGuilds(userID string) (st []*Guild, err error) { +func (s *Session) UserGuilds() (st []*Guild, err error) { - body, err := s.Request("GET", USER_GUILDS(userID), nil) + body, err := s.Request("GET", USER_GUILDS("@me"), nil) err = json.Unmarshal(body, &st) return } From a639011a066aafb41510f6e1ef110db2240ceb9b Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sun, 10 Jan 2016 21:39:18 -0800 Subject: [PATCH 3/4] Add attachments fields. --- message.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/message.go b/message.go index 63e7d3e..870c1da 100644 --- a/message.go +++ b/message.go @@ -30,7 +30,14 @@ type Message struct { } // An Attachment stores data for message attachments. -type Attachment struct { //TODO figure this out +type Attachment struct { + Width int `json:"width"` + URL string `json:"url"` + Size int `json:"size"` + ProxyURL string `json:"proxy_url"` + ID string `json:"id"` + Height int `json:"height"` + Filename string `json:"filename"` } // An Embed stores data for message embeds. From 735b01b158b13be822e5ce93a43417d777115446 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sun, 10 Jan 2016 22:12:45 -0800 Subject: [PATCH 4/4] Embeds. --- message.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/message.go b/message.go index 870c1da..59d0297 100644 --- a/message.go +++ b/message.go @@ -31,17 +31,40 @@ type Message struct { // An Attachment stores data for message attachments. type Attachment struct { - Width int `json:"width"` - URL string `json:"url"` - Size int `json:"size"` - ProxyURL string `json:"proxy_url"` ID string `json:"id"` + URL string `json:"url"` + ProxyURL string `json:"proxy_url"` + Width int `json:"width"` Height int `json:"height"` Filename string `json:"filename"` + Size int `json:"size"` } // An Embed stores data for message embeds. -type Embed struct { // TODO figure this out +type Embed struct { + URL string `json:"url"` + Type string `json:"type"` + Title string `json:"title"` + Description string `json:"description"` + Thumbnail *struct { + URL string `json:"url"` + ProxyURL string `json:"proxy_url"` + Width int `json:"width"` + Height int `json:"height"` + } `json:"thumbnail"` + Provider *struct { + URL string `json:"url"` + Name string `json:"name"` + } `json:"provider"` + Author *struct { + URL string `json:"url"` + Name string `json:"name"` + } `json:"author"` + Video *struct { + URL string `json:"url"` + Width int `json:"width"` + Height int `json:"height"` + } `json:"video"` } // ContentWithMentionsReplaced will replace all @ mentions with the