Discord: Added Relationship API methods; moved structs around

This commit is contained in:
diamondburned 2020-07-14 18:01:24 -07:00
parent 56b1a7cce8
commit 7572caad31
4 changed files with 43 additions and 20 deletions

View File

@ -100,3 +100,24 @@ func (c *Client) SetNote(userID discord.Snowflake, note string) error {
httputil.WithJSONBody(body),
)
}
// SetRelationship sets the relationship type between the current user and the
// given user.
func (c *Client) SetRelationship(userID discord.Snowflake, t discord.RelationshipType) error {
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.
func (c *Client) DeleteRelationship(userID discord.Snowflake) error {
return c.FastRequest("DELETE", EndpointMe+"/relationships/"+userID.String())
}

View File

@ -200,3 +200,22 @@ type ActivitySecrets struct {
Spectate string `json:"spectate,omitempty"`
Match string `json:"match,omitempty"`
}
// A Relationship between the logged in user and the user in the struct. This
// struct is undocumented.
type Relationship struct {
UserID Snowflake `json:"id"`
User User `json:"user"`
Type RelationshipType `json:"type"`
}
// RelationshipType is an enum for a relationship.
type RelationshipType uint8
const (
_ RelationshipType = iota
FriendRelationship
BlockedRelationship
IncomingFriendRequest
SentFriendRequest
)

View File

@ -329,9 +329,9 @@ type (
type (
RelationshipAddEvent struct {
Relationship
discord.Relationship
}
RelationshipRemoveEvent struct {
Relationship
discord.Relationship
}
)

View File

@ -20,7 +20,7 @@ type ReadyEvent struct {
ReadState []ReadState `json:"read_state,omitempty"`
Presences []discord.Presence `json:"presences,omitempty"`
Relationships []Relationship `json:"relationships,omitempty"`
Relationships []discord.Relationship `json:"relationships,omitempty"`
Notes map[discord.Snowflake]string `json:"notes,omitempty"`
}
@ -112,20 +112,3 @@ type GuildFolder struct {
GuildIDs []discord.Snowflake `json:"guild_ids"`
Color discord.Color `json:"color"`
}
// A Relationship between the logged in user and Relationship.User
type Relationship struct {
UserID discord.Snowflake `json:"id"`
User discord.User `json:"user"`
Type RelationshipType `json:"type"`
}
type RelationshipType uint8
const (
_ RelationshipType = iota
FriendRelationship
BlockedRelationship
IncomingFriendRequest
SentFriendRequest
)