|
@@ -3,7 +3,7 @@
|
|
* A Discord API for Golang.
|
|
* A Discord API for Golang.
|
|
* See discord.go for more information.
|
|
* See discord.go for more information.
|
|
*
|
|
*
|
|
- * This file contains functions for interacting with the Discord HTTPHTTP REST API
|
|
|
|
|
|
+ * This file contains functions for interacting with the Discord HTTP REST API
|
|
* at the lowest level.
|
|
* at the lowest level.
|
|
*/
|
|
*/
|
|
|
|
|
|
@@ -27,7 +27,6 @@ func Request(session *Session, method, urlStr, body string) (response []byte, er
|
|
fmt.Println("REQUEST :: " + method + " " + urlStr + "\n" + body)
|
|
fmt.Println("REQUEST :: " + method + " " + urlStr + "\n" + body)
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO: not sure if the NewBuffer is really needed always?
|
|
|
|
req, err := http.NewRequest(method, urlStr, bytes.NewBuffer([]byte(body)))
|
|
req, err := http.NewRequest(method, urlStr, bytes.NewBuffer([]byte(body)))
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
@@ -93,6 +92,10 @@ func Users(session *Session, userId string) (user User, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// USERS could pull users channels, servers, settings and so forth too?
|
|
|
|
+// you know, pull all the data for the user. update the user strut
|
|
|
|
+// to house that data. Seems reasonable.
|
|
|
|
+
|
|
// PrivateChannels returns an array of Channel structures for all private
|
|
// PrivateChannels returns an array of Channel structures for all private
|
|
// channels for a user
|
|
// channels for a user
|
|
func PrivateChannels(session *Session, userId string) (channels []Channel, err error) {
|
|
func PrivateChannels(session *Session, userId string) (channels []Channel, err error) {
|
|
@@ -112,6 +115,9 @@ func Servers(session *Session, userId string) (servers []Server, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// add one to get specific server by ID, or enhance the above with an ID field.
|
|
|
|
+// GET http://discordapp.com/api/guilds/ID#
|
|
|
|
+
|
|
// Members returns an array of Member structures for all members of a given
|
|
// Members returns an array of Member structures for all members of a given
|
|
// server.
|
|
// server.
|
|
func Members(session *Session, serverId int) (members []Member, err error) {
|
|
func Members(session *Session, serverId int) (members []Member, err error) {
|
|
@@ -132,6 +138,10 @@ func Channels(session *Session, serverId int) (channels []Channel, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// update above or add a way to get channel by ID. ChannelByName could be handy
|
|
|
|
+// too you know.
|
|
|
|
+// http://discordapp.com/api/channels/ID#
|
|
|
|
+
|
|
// Messages returns an array of Message structures for messaages within a given
|
|
// Messages returns an array of Message structures for messaages within a given
|
|
// channel. limit, beforeId, and afterId can be used to control what messages
|
|
// channel. limit, beforeId, and afterId can be used to control what messages
|
|
// are returned.
|
|
// are returned.
|
|
@@ -179,6 +189,18 @@ func SendMessage(session *Session, channelId int, content string) (message Messa
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Returns the a websocket Gateway address
|
|
|
|
+// session : An active session connection to Discord
|
|
|
|
+func Gateway(session *Session) (gateway string, err error) {
|
|
|
|
+
|
|
|
|
+ response, err := Request(session, "GET", fmt.Sprintf("%s/gateway", discordApi), ``)
|
|
|
|
+
|
|
|
|
+ var temp map[string]interface{}
|
|
|
|
+ err = json.Unmarshal(response, &temp)
|
|
|
|
+ gateway = temp["url"].(string)
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
// Close ends a session and logs out from the Discord REST API.
|
|
// Close ends a session and logs out from the Discord REST API.
|
|
// This does not seem to actually invalidate the token. So you can still
|
|
// This does not seem to actually invalidate the token. So you can still
|
|
// make API calls even after a Logout. So, it seems almost pointless to
|
|
// make API calls even after a Logout. So, it seems almost pointless to
|