2020-01-06 03:48:39 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-06 05:22:26 +00:00
|
|
|
import (
|
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-04-09 02:28:40 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/httputil"
|
2020-05-11 22:06:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/json/option"
|
2020-01-06 05:22:26 +00:00
|
|
|
)
|
2020-01-06 03:48:39 +00:00
|
|
|
|
2020-04-19 16:30:12 +00:00
|
|
|
var (
|
|
|
|
EndpointUsers = Endpoint + "users/"
|
|
|
|
EndpointMe = EndpointUsers + "@me"
|
|
|
|
)
|
2020-01-06 03:48:39 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// User returns a user object for a given user ID.
|
2020-01-06 03:48:39 +00:00
|
|
|
func (c *Client) User(userID discord.Snowflake) (*discord.User, error) {
|
|
|
|
var u *discord.User
|
2020-05-12 02:05:08 +00:00
|
|
|
return u, c.RequestJSON(&u, "GET", EndpointUsers+userID.String())
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Me returns the user object of the requester's account. For OAuth2, this
|
|
|
|
// requires the identify scope, which will return the object without an email,
|
|
|
|
// and optionally the email scope, which returns the object with an email.
|
2020-01-06 03:48:39 +00:00
|
|
|
func (c *Client) Me() (*discord.User, error) {
|
|
|
|
var me *discord.User
|
|
|
|
return me, c.RequestJSON(&me, "GET", EndpointMe)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/user#modify-current-user-json-params
|
2020-01-06 03:48:39 +00:00
|
|
|
type ModifySelfData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Username is the user's username, if changed may cause the user's
|
|
|
|
// discriminator to be randomized.
|
|
|
|
Username option.String `json:"username,omitempty"`
|
|
|
|
// Avatar modifies the user's avatar.
|
|
|
|
Avatar *Image `json:"image,omitempty"`
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ModifyMe modifies the requester's user account settings.
|
2020-01-06 03:48:39 +00:00
|
|
|
func (c *Client) ModifyMe(data ModifySelfData) (*discord.User, error) {
|
|
|
|
var u *discord.User
|
2020-05-11 22:06:19 +00:00
|
|
|
return u, c.RequestJSON(&u, "PATCH", EndpointMe, httputil.WithJSONBody(data))
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// PrivateChannels returns a list of DM channel objects. For bots, this is no
|
|
|
|
// longer a supported method of getting recent DMs, and will return an empty
|
|
|
|
// array.
|
2020-01-07 06:45:29 +00:00
|
|
|
func (c *Client) PrivateChannels() ([]discord.Channel, error) {
|
|
|
|
var dms []discord.Channel
|
|
|
|
return dms, c.RequestJSON(&dms, "GET", EndpointMe+"/channels")
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// CreatePrivateChannel creates a new DM channel with a user.
|
|
|
|
func (c *Client) CreatePrivateChannel(recipientID discord.Snowflake) (*discord.Channel, error) {
|
2020-01-07 06:45:29 +00:00
|
|
|
var param struct {
|
|
|
|
RecipientID discord.Snowflake `json:"recipient_id"`
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
param.RecipientID = recipientID
|
2020-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
var dm *discord.Channel
|
2020-05-12 02:05:08 +00:00
|
|
|
return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels", httputil.WithJSONBody(param))
|
2020-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
// ChangeOwnNickname only replies with the nickname back, so we're not even
|
|
|
|
// going to bother.
|
|
|
|
func (c *Client) ChangeOwnNickname(
|
|
|
|
guildID discord.Snowflake, nick string) error {
|
|
|
|
|
|
|
|
var param struct {
|
|
|
|
Nick string `json:"nick"`
|
|
|
|
}
|
|
|
|
|
|
|
|
param.Nick = nick
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/members/@me/nick",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(param),
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-01-07 06:45:29 +00:00
|
|
|
// shitty SDK, don't care, PR welcomed
|
|
|
|
// func (c *Client) CreateGroup(tokens []string, nicks map[])
|
|
|
|
|
2020-01-15 04:43:34 +00:00
|
|
|
// func (c *Client) UserConnections() ([]discord.Connection, error) {}
|