2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-01-02 19:55:45 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord"
|
|
|
|
"github.com/diamondburned/arikawa/httputil"
|
|
|
|
"github.com/diamondburned/arikawa/json"
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const EndpointChannels = Endpoint + "channels/"
|
|
|
|
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) Channels(
|
|
|
|
guildID discord.Snowflake) ([]discord.Channel, error) {
|
|
|
|
|
2020-01-05 07:50:22 +00:00
|
|
|
var chs []discord.Channel
|
|
|
|
return chs, c.RequestJSON(&chs, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/channels")
|
|
|
|
}
|
|
|
|
|
|
|
|
type CreateChannelData struct {
|
|
|
|
Name string `json:"name"` // 2-100
|
|
|
|
Topic string `json:"topic,omitempty"`
|
|
|
|
|
|
|
|
Type discord.ChannelType `json:"type,omitempty"`
|
|
|
|
|
|
|
|
VoiceBitrate uint `json:"bitrate,omitempty"`
|
|
|
|
VoiceUserLimit uint `json:"user_limit,omitempty"`
|
|
|
|
|
|
|
|
UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
|
|
|
|
|
|
|
|
NSFW bool `json:"nsfw"`
|
|
|
|
Position int `json:"position,omitempty"`
|
|
|
|
|
|
|
|
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
|
|
|
CategoryID discord.Snowflake `json:"parent_id,string,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) CreateChannel(
|
|
|
|
guildID discord.Snowflake,
|
2020-01-05 07:50:22 +00:00
|
|
|
data CreateChannelData) (*discord.Channel, error) {
|
|
|
|
|
|
|
|
var ch *discord.Channel
|
|
|
|
return ch, c.RequestJSON(
|
|
|
|
&ch, "POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/channels",
|
|
|
|
httputil.WithJSONBody(c, data),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) MoveChannel(
|
|
|
|
guildID, channelID discord.Snowflake, position int) error {
|
|
|
|
|
|
|
|
var param struct {
|
|
|
|
ID discord.Snowflake `json:"id"`
|
|
|
|
Pos int `json:"position"`
|
|
|
|
}
|
|
|
|
|
|
|
|
param.ID = channelID
|
|
|
|
param.Pos = position
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/channels",
|
|
|
|
httputil.WithJSONBody(c, param),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Channel(
|
|
|
|
channelID discord.Snowflake) (*discord.Channel, error) {
|
|
|
|
|
|
|
|
var channel *discord.Channel
|
|
|
|
|
|
|
|
return channel,
|
|
|
|
c.RequestJSON(&channel, "POST", EndpointChannels+channelID.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
type ModifyChannelData struct {
|
2020-01-04 04:19:24 +00:00
|
|
|
ChannelID discord.Snowflake `json:"id,string,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// All types
|
2020-01-02 19:53:08 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Position json.OptionInt `json:"position,omitempty"`
|
|
|
|
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// Text only
|
|
|
|
Topic json.OptionString `json:"topic,omitempty"`
|
|
|
|
NSFW json.OptionBool `json:"nsfw,omitempty"`
|
|
|
|
|
|
|
|
// 0-21600, refer to Channel.UserRateLimit
|
|
|
|
UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
|
|
|
|
|
|
|
|
// Voice only
|
|
|
|
// 8000 - 96000 (or 128000 for Nitro)
|
2020-01-05 07:50:22 +00:00
|
|
|
VoiceBitrate json.OptionUint `json:"bitrate,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
// 0 no limit, 1-99
|
2020-01-05 07:50:22 +00:00
|
|
|
VoiceUserLimit json.OptionUint `json:"user_limit,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// Text OR Voice
|
2020-01-05 07:50:22 +00:00
|
|
|
CategoryID discord.Snowflake `json:"parent_id,string,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 07:50:22 +00:00
|
|
|
func (c *Client) ModifyChannel(data ModifyChannelData) error {
|
|
|
|
url := EndpointChannels + data.ChannelID.String()
|
|
|
|
data.ChannelID = 0
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-01-05 07:50:22 +00:00
|
|
|
return c.FastRequest("PATCH", url, httputil.WithJSONBody(c, data))
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteChannel(channelID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("DELETE", EndpointChannels+channelID.String())
|
|
|
|
}
|
|
|
|
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) EditChannelPermission(
|
|
|
|
channelID discord.Snowflake, overwrite discord.Overwrite) error {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
url := EndpointChannels + channelID.String() + "/permissions/" +
|
|
|
|
overwrite.ID.String()
|
|
|
|
overwrite.ID = 0
|
|
|
|
|
|
|
|
return c.FastRequest("PUT", url, httputil.WithJSONBody(c, overwrite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteChannelPermission(
|
|
|
|
channelID, overwriteID discord.Snowflake) error {
|
|
|
|
|
|
|
|
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+
|
|
|
|
"/permissions/"+overwriteID.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Typing posts a typing indicator to the channel. Undocumented, but the client
|
|
|
|
// usually clears the typing indicator after 8-10 seconds (or after a message).
|
|
|
|
func (c *Client) Typing(channelID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("POST",
|
|
|
|
EndpointChannels+channelID.String()+"/typing")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PinnedMessages(
|
2020-01-02 19:53:08 +00:00
|
|
|
channelID discord.Snowflake) ([]discord.Message, error) {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
var pinned []discord.Message
|
2020-01-02 05:39:52 +00:00
|
|
|
return pinned, c.RequestJSON(&pinned, "GET",
|
|
|
|
EndpointChannels+channelID.String()+"/pins")
|
|
|
|
}
|
|
|
|
|
|
|
|
// PinMessage pins a message, which requires MANAGE_MESSAGES/
|
|
|
|
func (c *Client) PinMessage(channelID, messageID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("PUT",
|
|
|
|
EndpointChannels+channelID.String()+"/pins/"+messageID.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnpinMessage also requires MANAGE_MESSAGES.
|
|
|
|
func (c *Client) UnpinMessage(channelID, messageID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("DELETE",
|
|
|
|
EndpointChannels+channelID.String()+"/pins/"+messageID.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddRecipient adds a user to a group direct message. As accessToken is needed,
|
|
|
|
// clearly this endpoint should only be used for OAuth. AccessToken can be
|
|
|
|
// obtained with the "gdm.join" scope.
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) AddRecipient(
|
|
|
|
channelID, userID discord.Snowflake, accessToken, nickname string) error {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
var params struct {
|
|
|
|
AccessToken string `json:"access_token"`
|
|
|
|
Nickname string `json:"nickname"`
|
|
|
|
}
|
|
|
|
|
|
|
|
params.AccessToken = accessToken
|
|
|
|
params.Nickname = nickname
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"PUT",
|
|
|
|
EndpointChannels+channelID.String()+"/recipients/"+userID.String(),
|
|
|
|
httputil.WithJSONBody(c, params),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveRecipient removes a user from a group direct message.
|
|
|
|
func (c *Client) RemoveRecipient(channelID, userID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("DELETE",
|
|
|
|
EndpointChannels+channelID.String()+"/recipients/"+userID.String())
|
|
|
|
}
|