mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-27 17:23:00 +00:00
API: code cleanup
This commit is contained in:
parent
ae14c8fb73
commit
fb3ea3ce10
|
@ -9,8 +9,7 @@ import (
|
||||||
// Member returns a guild member object for the specified user..
|
// Member returns a guild member object for the specified user..
|
||||||
func (c *Client) Member(guildID, userID discord.Snowflake) (*discord.Member, error) {
|
func (c *Client) Member(guildID, userID discord.Snowflake) (*discord.Member, error) {
|
||||||
var m *discord.Member
|
var m *discord.Member
|
||||||
return m, c.RequestJSON(&m, "GET",
|
return m, c.RequestJSON(&m, "GET", EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
||||||
EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Members returns members until it reaches max. This function automatically
|
// Members returns members until it reaches max. This function automatically
|
||||||
|
@ -219,8 +218,10 @@ func (c *Client) Prune(guildID discord.Snowflake, days uint) (uint, error) {
|
||||||
// Requires KICK_MEMBERS permission.
|
// Requires KICK_MEMBERS permission.
|
||||||
// Fires a Guild Member Remove Gateway event.
|
// Fires a Guild Member Remove Gateway event.
|
||||||
func (c *Client) Kick(guildID, userID discord.Snowflake) error {
|
func (c *Client) Kick(guildID, userID discord.Snowflake) error {
|
||||||
return c.FastRequest("DELETE",
|
return c.FastRequest(
|
||||||
EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
"DELETE",
|
||||||
|
EndpointGuilds+guildID.String()+"/members/"+userID.String(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bans returns a list of ban objects for the users banned from this guild.
|
// Bans returns a list of ban objects for the users banned from this guild.
|
||||||
|
@ -228,8 +229,10 @@ func (c *Client) Kick(guildID, userID discord.Snowflake) error {
|
||||||
// Requires the BAN_MEMBERS permission.
|
// Requires the BAN_MEMBERS permission.
|
||||||
func (c *Client) Bans(guildID discord.Snowflake) ([]discord.Ban, error) {
|
func (c *Client) Bans(guildID discord.Snowflake) ([]discord.Ban, error) {
|
||||||
var bans []discord.Ban
|
var bans []discord.Ban
|
||||||
return bans, c.RequestJSON(&bans, "GET",
|
return bans, c.RequestJSON(
|
||||||
EndpointGuilds+guildID.String()+"/bans")
|
&bans, "GET",
|
||||||
|
EndpointGuilds+guildID.String()+"/bans",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBan returns a ban object for the given user.
|
// GetBan returns a ban object for the given user.
|
||||||
|
@ -237,8 +240,10 @@ func (c *Client) Bans(guildID discord.Snowflake) ([]discord.Ban, error) {
|
||||||
// Requires the BAN_MEMBERS permission.
|
// Requires the BAN_MEMBERS permission.
|
||||||
func (c *Client) GetBan(guildID, userID discord.Snowflake) (*discord.Ban, error) {
|
func (c *Client) GetBan(guildID, userID discord.Snowflake) (*discord.Ban, error) {
|
||||||
var ban *discord.Ban
|
var ban *discord.Ban
|
||||||
return ban, c.RequestJSON(&ban, "GET",
|
return ban, c.RequestJSON(
|
||||||
EndpointGuilds+guildID.String()+"/bans/"+userID.String())
|
&ban, "GET",
|
||||||
|
EndpointGuilds+guildID.String()+"/bans/"+userID.String(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#create-guild-ban-query-string-params
|
// https://discord.com/developers/docs/resources/guild#create-guild-ban-query-string-params
|
||||||
|
|
|
@ -179,6 +179,9 @@ func (c *Client) DeleteMessages(channelID discord.Snowflake, messageIDs []discor
|
||||||
|
|
||||||
param.Messages = messageIDs
|
param.Messages = messageIDs
|
||||||
|
|
||||||
return c.FastRequest("POST", EndpointChannels+channelID.String()+
|
return c.FastRequest(
|
||||||
"/messages/bulk-delete", httputil.WithJSONBody(param))
|
"POST",
|
||||||
|
EndpointChannels+channelID.String()+"/messages/bulk-delete",
|
||||||
|
httputil.WithJSONBody(param),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,23 +7,21 @@ import (
|
||||||
"github.com/diamondburned/arikawa/utils/httputil"
|
"github.com/diamondburned/arikawa/utils/httputil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// React creates a reaction for the message.
|
// React creates a reaction for the message.
|
||||||
//
|
//
|
||||||
// This endpoint requires the READ_MESSAGE_HISTORY permission to be present on
|
// This endpoint requires the READ_MESSAGE_HISTORY permission to be present on
|
||||||
// the current user. Additionally, if nobody else has reacted to the message
|
// the current user. Additionally, if nobody else has reacted to the message
|
||||||
// using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to
|
// using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to
|
||||||
// be present on the current user.
|
// be present on the current user.
|
||||||
func (c *Client) React(channelID, messageID discord.Snowflake, emoji EmojiAPI) error {
|
func (c *Client) React(channelID, messageID discord.Snowflake, emoji Emoji) error {
|
||||||
var msgURL = EndpointChannels + channelID.String() +
|
var msgURL = EndpointChannels + channelID.String() +
|
||||||
"/messages/" + messageID.String() +
|
"/messages/" + messageID.String() +
|
||||||
"/reactions/" + url.PathEscape(emoji) + "/@me"
|
"/reactions/" + url.PathEscape(emoji) + "/@me"
|
||||||
return c.FastRequest("PUT", msgURL)
|
return c.FastRequest("PUT", msgURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Unreact removes a reaction the current user has made for the message.
|
// Unreact removes a reaction the current user has made for the message.
|
||||||
func (c *Client) Unreact(chID, msgID discord.Snowflake, emoji EmojiAPI) error {
|
func (c *Client) Unreact(chID, msgID discord.Snowflake, emoji Emoji) error {
|
||||||
return c.DeleteUserReaction(chID, msgID, 0, emoji)
|
return c.DeleteUserReaction(chID, msgID, 0, emoji)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ func (c *Client) Unreact(chID, msgID discord.Snowflake, emoji EmojiAPI) error {
|
||||||
//
|
//
|
||||||
// Max can be 0, in which case the function will try and fetch all reactions.
|
// Max can be 0, in which case the function will try and fetch all reactions.
|
||||||
func (c *Client) Reactions(
|
func (c *Client) Reactions(
|
||||||
channelID, messageID discord.Snowflake, max uint, emoji EmojiAPI) ([]discord.User, error) {
|
channelID, messageID discord.Snowflake, max uint, emoji Emoji) ([]discord.User, error) {
|
||||||
|
|
||||||
var users []discord.User
|
var users []discord.User
|
||||||
var after discord.Snowflake = 0
|
var after discord.Snowflake = 0
|
||||||
|
@ -117,16 +115,18 @@ func (c *Client) ReactionsRange(
|
||||||
// This endpoint requires the MANAGE_MESSAGES permission to be present on the
|
// This endpoint requires the MANAGE_MESSAGES permission to be present on the
|
||||||
// current user.
|
// current user.
|
||||||
func (c *Client) DeleteUserReaction(
|
func (c *Client) DeleteUserReaction(
|
||||||
channelID, messageID, userID discord.Snowflake, emoji EmojiAPI) error {
|
channelID, messageID, userID discord.Snowflake, emoji Emoji) error {
|
||||||
|
|
||||||
var user = "@me"
|
var user = "@me"
|
||||||
if userID > 0 {
|
if userID > 0 {
|
||||||
user = userID.String()
|
user = userID.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.FastRequest("DELETE", EndpointChannels+chID.String()+
|
return c.FastRequest(
|
||||||
"/messages/"+msgID.String()+
|
"DELETE",
|
||||||
"/reactions/"+url.PathEscape(emoji)+"/"+user)
|
EndpointChannels+channelID.String()+"/messages/"+messageID.String()+
|
||||||
|
"/reactions/"+url.PathEscape(emoji)+"/"+user,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteReactions deletes all the reactions for a given emoji on a message.
|
// DeleteReactions deletes all the reactions for a given emoji on a message.
|
||||||
|
@ -135,7 +135,7 @@ func (c *Client) DeleteUserReaction(
|
||||||
// current user.
|
// current user.
|
||||||
// Fires a Message Reaction Remove Emoji Gateway event.
|
// Fires a Message Reaction Remove Emoji Gateway event.
|
||||||
func (c *Client) DeleteReactions(
|
func (c *Client) DeleteReactions(
|
||||||
channelId, messageID discord.Snowflake, emoji EmojiAPI) error {
|
channelId, messageID discord.Snowflake, emoji Emoji) error {
|
||||||
|
|
||||||
return c.FastRequest(
|
return c.FastRequest(
|
||||||
"DELETE",
|
"DELETE",
|
||||||
|
@ -150,6 +150,8 @@ func (c *Client) DeleteReactions(
|
||||||
// current user.
|
// current user.
|
||||||
// Fires a Message Reaction Remove All Gateway event.
|
// Fires a Message Reaction Remove All Gateway event.
|
||||||
func (c *Client) DeleteAllReactions(channelID, messageID discord.Snowflake) error {
|
func (c *Client) DeleteAllReactions(channelID, messageID discord.Snowflake) error {
|
||||||
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+
|
return c.FastRequest(
|
||||||
"/messages/"+messageID.String()+"/reactions/")
|
"DELETE",
|
||||||
|
EndpointChannels+channelID.String()+"/messages/"+messageID.String()+"/reactions/",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
23
api/role.go
23
api/role.go
|
@ -10,9 +10,10 @@ import (
|
||||||
//
|
//
|
||||||
// Requires the MANAGE_ROLES permission.
|
// Requires the MANAGE_ROLES permission.
|
||||||
func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
|
func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
|
||||||
return c.FastRequest("PUT", EndpointGuilds+guildID.String()+
|
return c.FastRequest(
|
||||||
"/members/"+userID.String()+
|
"PUT",
|
||||||
"/roles/"+roleID.String())
|
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveRole removes a role from a guild member.
|
// RemoveRole removes a role from a guild member.
|
||||||
|
@ -20,16 +21,16 @@ func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
|
||||||
// Requires the MANAGE_ROLES permission.
|
// Requires the MANAGE_ROLES permission.
|
||||||
// Fires a Guild Member Update Gateway event.
|
// Fires a Guild Member Update Gateway event.
|
||||||
func (c *Client) RemoveRole(guildID, userID, roleID discord.Snowflake) error {
|
func (c *Client) RemoveRole(guildID, userID, roleID discord.Snowflake) error {
|
||||||
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+
|
return c.FastRequest(
|
||||||
"/members/"+userID.String()+
|
"DELETE",
|
||||||
"/roles/"+roleID.String())
|
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Roles returns a list of role objects for the guild.
|
// Roles returns a list of role objects for the guild.
|
||||||
func (c *Client) Roles(guildID discord.Snowflake) ([]discord.Role, error) {
|
func (c *Client) Roles(guildID discord.Snowflake) ([]discord.Role, error) {
|
||||||
var roles []discord.Role
|
var roles []discord.Role
|
||||||
return roles, c.RequestJSON(&roles, "GET",
|
return roles, c.RequestJSON(&roles, "GET", EndpointGuilds+guildID.String()+"/roles")
|
||||||
EndpointGuilds+guildID.String()+"/roles")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/guild#create-guild-role-json-params
|
// https://discord.com/developers/docs/resources/guild#create-guild-role-json-params
|
||||||
|
@ -127,6 +128,8 @@ func (c *Client) ModifyRole(
|
||||||
//
|
//
|
||||||
// Requires the MANAGE_ROLES permission.
|
// Requires the MANAGE_ROLES permission.
|
||||||
func (c *Client) DeleteRole(guildID, roleID discord.Snowflake) error {
|
func (c *Client) DeleteRole(guildID, roleID discord.Snowflake) error {
|
||||||
return c.FastRequest("DELETE",
|
return c.FastRequest(
|
||||||
EndpointGuilds+guildID.String()+"/roles/"+roleID.String())
|
"DELETE",
|
||||||
|
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,7 @@ var (
|
||||||
// User returns a user object for a given user ID.
|
// User returns a user object for a given user ID.
|
||||||
func (c *Client) User(userID discord.Snowflake) (*discord.User, error) {
|
func (c *Client) User(userID discord.Snowflake) (*discord.User, error) {
|
||||||
var u *discord.User
|
var u *discord.User
|
||||||
return u, c.RequestJSON(&u, "GET",
|
return u, c.RequestJSON(&u, "GET", EndpointUsers+userID.String())
|
||||||
EndpointUsers+userID.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Me returns the user object of the requester's account. For OAuth2, this
|
// Me returns the user object of the requester's account. For OAuth2, this
|
||||||
|
@ -58,8 +57,7 @@ func (c *Client) CreatePrivateChannel(recipientID discord.Snowflake) (*discord.C
|
||||||
param.RecipientID = recipientID
|
param.RecipientID = recipientID
|
||||||
|
|
||||||
var dm *discord.Channel
|
var dm *discord.Channel
|
||||||
return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels",
|
return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels", httputil.WithJSONBody(param))
|
||||||
httputil.WithJSONBody(param))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeOwnNickname only replies with the nickname back, so we're not even
|
// ChangeOwnNickname only replies with the nickname back, so we're not even
|
||||||
|
|
Loading…
Reference in a new issue