2020-01-06 03:48:39 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-06 05:22:26 +00:00
|
|
|
import (
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/utils/httputil"
|
|
|
|
"github.com/diamondburned/arikawa/v3/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-07-21 20:27:59 +00:00
|
|
|
func (c *Client) User(userID discord.UserID) (*discord.User, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
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
|
2021-09-28 18:46:36 +00:00
|
|
|
type ModifyCurrentUserData 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"`
|
2021-08-15 16:33:33 +00:00
|
|
|
|
|
|
|
AuditLogReason `json:"-"`
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 18:46:36 +00:00
|
|
|
// ModifyCurrentUser modifies the requester's user account settings.
|
|
|
|
func (c *Client) ModifyCurrentUser(data ModifyCurrentUserData) (*discord.User, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
var u *discord.User
|
2021-08-15 16:33:33 +00:00
|
|
|
return u, c.RequestJSON(
|
|
|
|
&u,
|
|
|
|
"PATCH", EndpointMe,
|
|
|
|
httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
|
|
|
|
)
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 18:46:36 +00:00
|
|
|
// ModifyCurrentMember modifies the nickname of the current user in a guild.
|
2020-05-15 17:29:04 +00:00
|
|
|
//
|
|
|
|
// Fires a Guild Member Update Gateway event.
|
2021-09-28 18:46:36 +00:00
|
|
|
func (c *Client) ModifyCurrentMember(
|
2020-07-21 20:27:59 +00:00
|
|
|
guildID discord.GuildID, nick string) error {
|
2020-05-15 17:29:04 +00:00
|
|
|
|
|
|
|
var param struct {
|
|
|
|
Nick string `json:"nick"`
|
|
|
|
}
|
|
|
|
|
|
|
|
param.Nick = nick
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
2021-09-28 18:46:36 +00:00
|
|
|
EndpointGuilds+guildID.String()+"/members/@me",
|
2020-05-15 17:29:04 +00:00
|
|
|
httputil.WithJSONBody(param),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) CreatePrivateChannel(recipientID discord.UserID) (*discord.Channel, error) {
|
2020-01-07 06:45:29 +00:00
|
|
|
var param struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
RecipientID discord.UserID `json:"recipient_id"`
|
2020-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
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-05-15 17:31:23 +00:00
|
|
|
// UserConnections returns a list of connection objects. Requires the
|
|
|
|
// connections OAuth2 scope.
|
|
|
|
func (c *Client) UserConnections() ([]discord.Connection, error) {
|
|
|
|
var conn []discord.Connection
|
|
|
|
return conn, c.RequestJSON(&conn, "GET", EndpointMe+"/connections")
|
2020-05-15 18:38:22 +00:00
|
|
|
}
|
2020-07-11 21:27:03 +00:00
|
|
|
|
2020-12-27 00:13:10 +00:00
|
|
|
// Note gets the note for the given user. This endpoint is undocumented and
|
|
|
|
// might only work for user accounts.
|
|
|
|
func (c *Client) Note(userID discord.UserID) (string, error) {
|
|
|
|
var body struct {
|
|
|
|
Note string `json:"note"`
|
|
|
|
}
|
|
|
|
|
|
|
|
return body.Note, c.RequestJSON(&body, "GET", EndpointMe+"/notes/"+userID.String())
|
|
|
|
}
|
|
|
|
|
2020-07-11 21:27:03 +00:00
|
|
|
// SetNote sets a note for the user. This endpoint is undocumented and might
|
|
|
|
// only work for user accounts.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) SetNote(userID discord.UserID, note string) error {
|
2020-07-11 21:27:03 +00:00
|
|
|
var body = struct {
|
|
|
|
Note string `json:"note"`
|
|
|
|
}{
|
|
|
|
Note: note,
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PUT", EndpointMe+"/notes/"+userID.String(),
|
|
|
|
httputil.WithJSONBody(body),
|
|
|
|
)
|
|
|
|
}
|
2020-07-15 01:01:24 +00:00
|
|
|
|
|
|
|
// SetRelationship sets the relationship type between the current user and the
|
|
|
|
// given user.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) SetRelationship(userID discord.UserID, t discord.RelationshipType) error {
|
2020-07-15 01:01:24 +00:00
|
|
|
var body = struct {
|
|
|
|
Type discord.RelationshipType `json:"type"`
|
|
|
|
}{
|
|
|
|
Type: t,
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PUT", EndpointMe+"/relationships/"+userID.String(),
|
|
|
|
httputil.WithJSONBody(body),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteRelationship deletes the relationship between the current user and the
|
|
|
|
// given user.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) DeleteRelationship(userID discord.UserID) error {
|
2020-07-15 01:01:24 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointMe+"/relationships/"+userID.String())
|
|
|
|
}
|