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..
|
||||
func (c *Client) Member(guildID, userID discord.Snowflake) (*discord.Member, error) {
|
||||
var m *discord.Member
|
||||
return m, c.RequestJSON(&m, "GET",
|
||||
EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
||||
return m, c.RequestJSON(&m, "GET", EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Fires a Guild Member Remove Gateway event.
|
||||
func (c *Client) Kick(guildID, userID discord.Snowflake) error {
|
||||
return c.FastRequest("DELETE",
|
||||
EndpointGuilds+guildID.String()+"/members/"+userID.String())
|
||||
return c.FastRequest(
|
||||
"DELETE",
|
||||
EndpointGuilds+guildID.String()+"/members/"+userID.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (c *Client) Bans(guildID discord.Snowflake) ([]discord.Ban, error) {
|
||||
var bans []discord.Ban
|
||||
return bans, c.RequestJSON(&bans, "GET",
|
||||
EndpointGuilds+guildID.String()+"/bans")
|
||||
return bans, c.RequestJSON(
|
||||
&bans, "GET",
|
||||
EndpointGuilds+guildID.String()+"/bans",
|
||||
)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (c *Client) GetBan(guildID, userID discord.Snowflake) (*discord.Ban, error) {
|
||||
var ban *discord.Ban
|
||||
return ban, c.RequestJSON(&ban, "GET",
|
||||
EndpointGuilds+guildID.String()+"/bans/"+userID.String())
|
||||
return ban, c.RequestJSON(
|
||||
&ban, "GET",
|
||||
EndpointGuilds+guildID.String()+"/bans/"+userID.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
return c.FastRequest("POST", EndpointChannels+channelID.String()+
|
||||
"/messages/bulk-delete", httputil.WithJSONBody(param))
|
||||
return c.FastRequest(
|
||||
"POST",
|
||||
EndpointChannels+channelID.String()+"/messages/bulk-delete",
|
||||
httputil.WithJSONBody(param),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -7,23 +7,21 @@ import (
|
|||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
)
|
||||
|
||||
|
||||
// React creates a reaction for the message.
|
||||
//
|
||||
// This endpoint requires the READ_MESSAGE_HISTORY permission to be present on
|
||||
// the current user. Additionally, if nobody else has reacted to the message
|
||||
// using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to
|
||||
// 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() +
|
||||
"/messages/" + messageID.String() +
|
||||
"/reactions/" + url.PathEscape(emoji) + "/@me"
|
||||
return c.FastRequest("PUT", msgURL)
|
||||
}
|
||||
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
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 after discord.Snowflake = 0
|
||||
|
@ -117,16 +115,18 @@ func (c *Client) ReactionsRange(
|
|||
// This endpoint requires the MANAGE_MESSAGES permission to be present on the
|
||||
// current user.
|
||||
func (c *Client) DeleteUserReaction(
|
||||
channelID, messageID, userID discord.Snowflake, emoji EmojiAPI) error {
|
||||
channelID, messageID, userID discord.Snowflake, emoji Emoji) error {
|
||||
|
||||
var user = "@me"
|
||||
if userID > 0 {
|
||||
user = userID.String()
|
||||
}
|
||||
|
||||
return c.FastRequest("DELETE", EndpointChannels+chID.String()+
|
||||
"/messages/"+msgID.String()+
|
||||
"/reactions/"+url.PathEscape(emoji)+"/"+user)
|
||||
return c.FastRequest(
|
||||
"DELETE",
|
||||
EndpointChannels+channelID.String()+"/messages/"+messageID.String()+
|
||||
"/reactions/"+url.PathEscape(emoji)+"/"+user,
|
||||
)
|
||||
}
|
||||
|
||||
// DeleteReactions deletes all the reactions for a given emoji on a message.
|
||||
|
@ -135,7 +135,7 @@ func (c *Client) DeleteUserReaction(
|
|||
// current user.
|
||||
// Fires a Message Reaction Remove Emoji Gateway event.
|
||||
func (c *Client) DeleteReactions(
|
||||
channelId, messageID discord.Snowflake, emoji EmojiAPI) error {
|
||||
channelId, messageID discord.Snowflake, emoji Emoji) error {
|
||||
|
||||
return c.FastRequest(
|
||||
"DELETE",
|
||||
|
@ -150,6 +150,8 @@ func (c *Client) DeleteReactions(
|
|||
// current user.
|
||||
// Fires a Message Reaction Remove All Gateway event.
|
||||
func (c *Client) DeleteAllReactions(channelID, messageID discord.Snowflake) error {
|
||||
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+
|
||||
"/messages/"+messageID.String()+"/reactions/")
|
||||
return c.FastRequest(
|
||||
"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.
|
||||
func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
|
||||
return c.FastRequest("PUT", EndpointGuilds+guildID.String()+
|
||||
"/members/"+userID.String()+
|
||||
"/roles/"+roleID.String())
|
||||
return c.FastRequest(
|
||||
"PUT",
|
||||
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// Fires a Guild Member Update Gateway event.
|
||||
func (c *Client) RemoveRole(guildID, userID, roleID discord.Snowflake) error {
|
||||
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+
|
||||
"/members/"+userID.String()+
|
||||
"/roles/"+roleID.String())
|
||||
return c.FastRequest(
|
||||
"DELETE",
|
||||
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
||||
)
|
||||
}
|
||||
|
||||
// Roles returns a list of role objects for the guild.
|
||||
func (c *Client) Roles(guildID discord.Snowflake) ([]discord.Role, error) {
|
||||
var roles []discord.Role
|
||||
return roles, c.RequestJSON(&roles, "GET",
|
||||
EndpointGuilds+guildID.String()+"/roles")
|
||||
return roles, c.RequestJSON(&roles, "GET", EndpointGuilds+guildID.String()+"/roles")
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (c *Client) DeleteRole(guildID, roleID discord.Snowflake) error {
|
||||
return c.FastRequest("DELETE",
|
||||
EndpointGuilds+guildID.String()+"/roles/"+roleID.String())
|
||||
return c.FastRequest(
|
||||
"DELETE",
|
||||
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@ var (
|
|||
// User returns a user object for a given user ID.
|
||||
func (c *Client) User(userID discord.Snowflake) (*discord.User, error) {
|
||||
var u *discord.User
|
||||
return u, c.RequestJSON(&u, "GET",
|
||||
EndpointUsers+userID.String())
|
||||
return u, c.RequestJSON(&u, "GET", EndpointUsers+userID.String())
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
var dm *discord.Channel
|
||||
return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels",
|
||||
httputil.WithJSONBody(param))
|
||||
return dm, c.RequestJSON(&dm, "POST", EndpointMe+"/channels", httputil.WithJSONBody(param))
|
||||
}
|
||||
|
||||
// ChangeOwnNickname only replies with the nickname back, so we're not even
|
||||
|
|
Loading…
Reference in a new issue