2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-01-02 19:55:45 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-04-09 02:28:40 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/httputil"
|
2020-05-11 01:14:30 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/json/option"
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
|
|
|
|
2020-04-19 16:30:12 +00:00
|
|
|
var EndpointChannels = Endpoint + "channels/"
|
2020-01-02 05:39:52 +00:00
|
|
|
|
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"`
|
|
|
|
|
2020-05-11 11:53:25 +00:00
|
|
|
Type discord.ChannelType `json:"type,omitempty"`
|
2020-01-05 07:50:22 +00:00
|
|
|
|
|
|
|
VoiceBitrate uint `json:"bitrate,omitempty"`
|
|
|
|
VoiceUserLimit uint `json:"user_limit,omitempty"`
|
|
|
|
|
|
|
|
UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
|
|
|
|
|
2020-05-11 03:24:59 +00:00
|
|
|
NSFW bool `json:"nsfw,omitempty"`
|
|
|
|
Position option.Int `json:"position,omitempty"`
|
2020-01-05 07:50:22 +00:00
|
|
|
|
|
|
|
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",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-05 07:50:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
type MoveChannelData struct {
|
|
|
|
ID discord.Snowflake `json:"id"`
|
2020-05-11 01:14:30 +00:00
|
|
|
Position option.Int `json:"position"`
|
2020-05-07 19:32:56 +00:00
|
|
|
}
|
2020-01-05 07:50:22 +00:00
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
// MoveChannel modifies the position of channels in the guild. Requires
|
|
|
|
// MANAGE_CHANNELS.
|
|
|
|
func (c *Client) MoveChannel(guildID discord.Snowflake, datum []MoveChannelData) error {
|
2020-01-05 07:50:22 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/channels",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(datum),
|
2020-01-05 07:50:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
func (c *Client) Channel(channelID discord.Snowflake) (*discord.Channel, error) {
|
2020-01-05 07:50:22 +00:00
|
|
|
var channel *discord.Channel
|
2020-05-07 19:32:56 +00:00
|
|
|
return channel, c.RequestJSON(&channel, "GET", EndpointChannels+channelID.String())
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ModifyChannelData struct {
|
2020-01-02 05:39:52 +00:00
|
|
|
// All types
|
2020-05-11 03:24:59 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
// Type allows conversions between text and news channels.
|
|
|
|
Type *discord.ChannelType `json:"type,omitempty"`
|
|
|
|
Position option.Int `json:"position,omitempty"`
|
|
|
|
Permissions *[]discord.Overwrite `json:"permission_overwrites,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// Text only
|
2020-05-11 01:14:30 +00:00
|
|
|
Topic option.String `json:"topic,omitempty"`
|
|
|
|
NSFW option.Bool `json:"nsfw,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-04-09 00:48:36 +00:00
|
|
|
// 0-21600 seconds, refer to (discord.Channel).UserRateLimit.
|
2020-05-11 01:14:30 +00:00
|
|
|
UserRateLimit option.Int `json:"rate_limit_per_user,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// Voice only
|
|
|
|
// 8000 - 96000 (or 128000 for Nitro)
|
2020-05-11 01:14:30 +00:00
|
|
|
VoiceBitrate option.Uint `json:"bitrate,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
// 0 no limit, 1-99
|
2020-05-11 01:14:30 +00:00
|
|
|
VoiceUserLimit option.Uint `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-04-09 00:57:44 +00:00
|
|
|
func (c *Client) ModifyChannel(channelID discord.Snowflake, data ModifyChannelData) error {
|
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointChannels+channelID.String(),
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-04-09 00:57:44 +00:00
|
|
|
)
|
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
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
url := EndpointChannels + channelID.String() + "/permissions/" + overwrite.ID.String()
|
2020-01-02 05:39:52 +00:00
|
|
|
overwrite.ID = 0
|
|
|
|
|
2020-05-08 03:43:46 +00:00
|
|
|
return c.FastRequest("PUT", url, httputil.WithJSONBody(overwrite))
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
func (c *Client) DeleteChannelPermission(channelID, overwriteID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("DELETE",
|
|
|
|
EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String())
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2020-05-07 19:32:56 +00:00
|
|
|
return c.FastRequest("POST", EndpointChannels+channelID.String()+"/typing")
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
func (c *Client) PinnedMessages(channelID discord.Snowflake) ([]discord.Message, error) {
|
2020-01-02 19:53:08 +00:00
|
|
|
var pinned []discord.Message
|
2020-05-07 19:32:56 +00:00
|
|
|
return pinned, c.RequestJSON(&pinned, "GET", EndpointChannels+channelID.String()+"/pins")
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PinMessage pins a message, which requires MANAGE_MESSAGES/
|
|
|
|
func (c *Client) PinMessage(channelID, messageID discord.Snowflake) error {
|
2020-05-07 19:32:56 +00:00
|
|
|
return c.FastRequest("PUT", EndpointChannels+channelID.String()+"/pins/"+messageID.String())
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnpinMessage also requires MANAGE_MESSAGES.
|
|
|
|
func (c *Client) UnpinMessage(channelID, messageID discord.Snowflake) error {
|
2020-05-07 19:32:56 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+"/pins/"+messageID.String())
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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(),
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(params),
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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())
|
|
|
|
}
|
2020-02-25 05:50:13 +00:00
|
|
|
|
2020-05-07 19:32:56 +00:00
|
|
|
// Ack is the read state of a channel. This is undocumented.
|
2020-02-25 05:50:13 +00:00
|
|
|
type Ack struct {
|
|
|
|
Token string `json:"token"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ack marks the read state of a channel. This is undocumented. The method will
|
2020-05-07 19:32:56 +00:00
|
|
|
// write to the ack variable passed in. If this method is called asynchronously,
|
|
|
|
// then ack should be mutex guarded.
|
2020-02-25 05:50:13 +00:00
|
|
|
func (c *Client) Ack(channelID, messageID discord.Snowflake, ack *Ack) error {
|
|
|
|
return c.RequestJSON(
|
|
|
|
ack, "POST",
|
|
|
|
EndpointChannels+channelID.String()+
|
|
|
|
"/messages/"+messageID.String()+"/ack",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(ack),
|
2020-02-25 05:50:13 +00:00
|
|
|
)
|
|
|
|
}
|