2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-10-28 22:39:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v2/utils/httputil"
|
|
|
|
"github.com/diamondburned/arikawa/v2/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-05-11 22:06:19 +00:00
|
|
|
// Channels returns a list of guild channel objects.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Channels(guildID discord.GuildID) ([]discord.Channel, error) {
|
2020-01-05 07:50:22 +00:00
|
|
|
var chs []discord.Channel
|
2020-05-11 22:06:19 +00:00
|
|
|
return chs, c.RequestJSON(&chs, "GET", EndpointGuilds+guildID.String()+"/channels")
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#create-guild-channel-json-params
|
2020-01-05 07:50:22 +00:00
|
|
|
type CreateChannelData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Name is the channel name (2-100 characters).
|
|
|
|
//
|
|
|
|
// Channel Type: All
|
|
|
|
Name string `json:"name"`
|
|
|
|
// Type is the type of channel.
|
|
|
|
//
|
|
|
|
// Channel Type: All
|
2020-05-11 11:53:25 +00:00
|
|
|
Type discord.ChannelType `json:"type,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Topic is the channel topic (0-1024 characters).
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News
|
|
|
|
Topic string `json:"topic,omitempty"`
|
|
|
|
// VoiceBitrate is the bitrate (in bits) of the voice channel.
|
|
|
|
// 8000 to 96000 (128000 for VIP servers)
|
|
|
|
//
|
|
|
|
// Channel Types: Voice
|
|
|
|
VoiceBitrate uint `json:"bitrate,omitempty"`
|
|
|
|
// VoiceUserLimit is the user limit of the voice channel.
|
|
|
|
// 0 refers to no limit, 1 to 99 refers to a user limit.
|
|
|
|
//
|
|
|
|
// Channel Types: Voice
|
2020-01-05 07:50:22 +00:00
|
|
|
VoiceUserLimit uint `json:"user_limit,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// UserRateLimit is the amount of seconds a user has to wait before sending
|
|
|
|
// another message (0-21600).
|
|
|
|
// Bots, as well as users with the permission manage_messages or
|
|
|
|
// manage_channel, are unaffected.
|
|
|
|
//
|
|
|
|
// Channel Types: Text
|
2020-01-05 07:50:22 +00:00
|
|
|
UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Position is the sorting position of the channel.
|
|
|
|
//
|
|
|
|
// Channel Types: All
|
2020-05-11 03:24:59 +00:00
|
|
|
Position option.Int `json:"position,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Permissions are the channel's permission overwrites.
|
|
|
|
//
|
|
|
|
// Channel Types: All
|
2020-01-05 07:50:22 +00:00
|
|
|
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// CategoryID is the id of the parent category for a channel.
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News, Store, Voice
|
2020-07-21 20:27:59 +00:00
|
|
|
CategoryID discord.ChannelID `json:"parent_id,string,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// NSFW specifies whether the channel is nsfw.
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News, Store.
|
|
|
|
NSFW bool `json:"nsfw,omitempty"`
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// CreateChannel creates a new channel object for the guild.
|
|
|
|
//
|
2021-05-29 17:47:50 +00:00
|
|
|
// Requires the MANAGE_CHANNELS permission. If setting permission overwrites,
|
|
|
|
// only permissions your bot has in the guild can be allowed/denied. Setting
|
|
|
|
// MANAGE_ROLES permission in channels is only possible for guild
|
|
|
|
// administrators. Returns the new channel object on success.
|
|
|
|
//
|
|
|
|
// Fires a ChannelCreate Gateway event.
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) CreateChannel(
|
2020-07-21 20:27:59 +00:00
|
|
|
guildID discord.GuildID, data CreateChannelData) (*discord.Channel, error) {
|
2020-01-05 07:50:22 +00:00
|
|
|
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 {
|
2020-05-11 22:06:19 +00:00
|
|
|
// ID is the channel id.
|
2020-07-21 20:27:59 +00:00
|
|
|
ID discord.ChannelID `json:"id"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Position is the sorting position of the channel
|
|
|
|
Position option.Int `json:"position"`
|
2020-05-07 19:32:56 +00:00
|
|
|
}
|
2020-01-05 07:50:22 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// MoveChannel modifies the position of channels in the guild.
|
|
|
|
//
|
|
|
|
// Requires MANAGE_CHANNELS.
|
2020-07-29 23:29:01 +00:00
|
|
|
func (c *Client) MoveChannel(guildID discord.GuildID, data []MoveChannelData) error {
|
2020-01-05 07:50:22 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
2020-07-29 23:29:01 +00:00
|
|
|
EndpointGuilds+guildID.String()+"/channels", httputil.WithJSONBody(data),
|
2020-01-05 07:50:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Channel gets a channel by ID. Returns a channel object.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Channel(channelID discord.ChannelID) (*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
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/channel#modify-channel-json-params
|
2020-01-05 07:50:22 +00:00
|
|
|
type ModifyChannelData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Name is the 2-100 character channel name.
|
|
|
|
//
|
|
|
|
// Channel Types: All
|
2020-05-11 03:24:59 +00:00
|
|
|
Name string `json:"name,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Type is the type of the channel.
|
|
|
|
// Only conversion between text and news is supported and only in guilds
|
|
|
|
// with the "NEWS" feature
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News
|
|
|
|
Type *discord.ChannelType `json:"type,omitempty"`
|
|
|
|
// Postion is the position of the channel in the left-hand listing
|
|
|
|
//
|
|
|
|
// Channel Types: All
|
|
|
|
Position option.NullableInt `json:"position,omitempty"`
|
|
|
|
// Topic is the 0-1024 character channel topic.
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News
|
|
|
|
Topic option.NullableString `json:"topic,omitempty"`
|
|
|
|
// NSFW specifies whether the channel is nsfw.
|
|
|
|
//
|
|
|
|
// Channel Types: Text, News, Store.
|
|
|
|
NSFW option.NullableBool `json:"nsfw,omitempty"`
|
|
|
|
// UserRateLimit is the amount of seconds a user has to wait before sending
|
|
|
|
// another message (0-21600).
|
|
|
|
// Bots, as well as users with the permission manage_messages or
|
|
|
|
// manage_channel, are unaffected.
|
|
|
|
//
|
|
|
|
// Channel Types: Text
|
|
|
|
UserRateLimit option.NullableUint `json:"rate_limit_per_user,omitempty"`
|
|
|
|
// VoiceBitrate is the bitrate (in bits) of the voice channel.
|
|
|
|
// 8000 to 96000 (128000 for VIP servers)
|
|
|
|
//
|
|
|
|
// Channel Types: Voice
|
|
|
|
VoiceBitrate option.NullableUint `json:"bitrate,omitempty"`
|
|
|
|
// VoiceUserLimit is the user limit of the voice channel.
|
|
|
|
// 0 refers to no limit, 1 to 99 refers to a user limit.
|
|
|
|
//
|
|
|
|
// Channel Types: Voice
|
|
|
|
VoiceUserLimit option.NullableUint `json:"user_limit,omitempty"`
|
|
|
|
// Permissions are the channel or category-specific permissions.
|
|
|
|
//
|
|
|
|
// Channel Types: All
|
2020-05-11 03:24:59 +00:00
|
|
|
Permissions *[]discord.Overwrite `json:"permission_overwrites,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// CategoryID is the id of the new parent category for a channel.
|
|
|
|
// Channel Types: Text, News, Store, Voice
|
2020-07-21 20:27:59 +00:00
|
|
|
CategoryID discord.ChannelID `json:"parent_id,string,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ModifyChannel updates a channel's settings.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_CHANNELS permission for the guild.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) ModifyChannel(channelID discord.ChannelID, data ModifyChannelData) error {
|
2020-05-11 22:06:19 +00:00
|
|
|
return c.FastRequest("PATCH", EndpointChannels+channelID.String(), httputil.WithJSONBody(data))
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// DeleteChannel deletes a channel, or closes a private message. Requires the
|
|
|
|
// MANAGE_CHANNELS permission for the guild. Deleting a category does not
|
|
|
|
// delete its child channels: they will have their parent_id removed and a
|
|
|
|
// Channel Update Gateway event will fire for each of them.
|
|
|
|
//
|
|
|
|
// Fires a Channel Delete Gateway event.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) DeleteChannel(channelID discord.ChannelID) error {
|
2020-01-02 05:39:52 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointChannels+channelID.String())
|
|
|
|
}
|
|
|
|
|
2020-08-18 00:10:43 +00:00
|
|
|
// https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params
|
2020-05-25 00:20:34 +00:00
|
|
|
type EditChannelPermissionData struct {
|
|
|
|
// Type is either "role" or "member".
|
2020-10-28 22:34:14 +00:00
|
|
|
Type discord.OverwriteType `json:"type"`
|
2020-05-25 00:20:34 +00:00
|
|
|
// Allow is a permission bit set for granted permissions.
|
2020-08-18 00:10:43 +00:00
|
|
|
Allow discord.Permissions `json:"allow,string"`
|
2020-05-25 00:20:34 +00:00
|
|
|
// Deny is a permission bit set for denied permissions.
|
2020-08-18 00:10:43 +00:00
|
|
|
Deny discord.Permissions `json:"deny,string"`
|
2020-05-25 00:20:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// EditChannelPermission edits the channel's permission overwrites for a user
|
|
|
|
// or role in a channel. Only usable for guild channels.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
2020-01-06 05:32:25 +00:00
|
|
|
func (c *Client) EditChannelPermission(
|
2020-07-21 20:27:59 +00:00
|
|
|
channelID discord.ChannelID, overwriteID discord.Snowflake, data EditChannelPermissionData) error {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-25 00:25:34 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PUT", EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String(),
|
|
|
|
httputil.WithJSONBody(data),
|
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// DeleteChannelPermission deletes a channel permission overwrite for a user or
|
|
|
|
// role in a channel. Only usable for guild channels.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
2020-07-29 23:29:01 +00:00
|
|
|
func (c *Client) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake) error {
|
2020-05-11 22:06:19 +00:00
|
|
|
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).
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Typing(channelID discord.ChannelID) 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-11 22:06:19 +00:00
|
|
|
// PinnedMessages returns all pinned messages in the channel as an array of
|
|
|
|
// message objects.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) PinnedMessages(channelID discord.ChannelID) ([]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
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// PinMessage pins a message in a channel.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_MESSAGES permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) PinMessage(channelID discord.ChannelID, messageID discord.MessageID) 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
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// UnpinMessage deletes a pinned message in a channel.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_MESSAGES permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) UnpinMessage(channelID discord.ChannelID, messageID discord.MessageID) 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-07-21 20:27:59 +00:00
|
|
|
func (c *Client) AddRecipient(channelID discord.ChannelID, userID discord.UserID, 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.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) RemoveRecipient(channelID discord.ChannelID, userID discord.UserID) error {
|
2020-05-11 22:06:19 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"DELETE",
|
|
|
|
EndpointChannels+channelID.String()+"/recipients/"+userID.String(),
|
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
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-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Ack(channelID discord.ChannelID, messageID discord.MessageID, ack *Ack) error {
|
2020-02-25 05:50:13 +00:00
|
|
|
return c.RequestJSON(
|
|
|
|
ack, "POST",
|
2020-05-11 22:06:19 +00:00
|
|
|
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
|
|
|
)
|
|
|
|
}
|