diff --git a/api/stage.go b/api/stage.go new file mode 100644 index 0000000..8456188 --- /dev/null +++ b/api/stage.go @@ -0,0 +1,60 @@ +package api + +import ( + "github.com/diamondburned/arikawa/v2/discord" + "github.com/diamondburned/arikawa/v2/utils/httputil" +) + +var EndpointStageInstances = Endpoint + "stage-instances/" + +// https://discord.com/developers/docs/resources/stage-instance#create-stage-instance-json-params +type CreateStageInstanceData struct { + // ChannelID is the id of the Stage channel. + ChannelID discord.ChannelID `json:"channel_id"` + // Topic is the topic of the Stage instance (1-120 characters). + Topic string `json:"topic"` + // PrivacyLevel is the privacy level of the Stage instance. + // + // Defaults to discord.GuildOnlyStage. + PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"` +} + +// CreateStageInstance creates a new Stage instance associated to a Stage +// channel. +// +// It requires the user to be a moderator of the Stage channel. +func (c *Client) CreateStageInstance( + data CreateStageInstanceData) (*discord.StageInstance, error) { + + var s *discord.StageInstance + return s, c.RequestJSON( + &s, "POST", + EndpointStageInstances, + httputil.WithJSONBody(data), + ) +} + +// https://discord.com/developers/docs/resources/stage-instance#update-stage-instance-json-params +type UpdateStageInstanceData struct { + // Topic is the topic of the Stage instance (1-120 characters). + Topic string `json:"topic,omitempty"` + // PrivacyLevel is the privacy level of the Stage instance. + PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"` +} + +// UpdateStageInstance updates fields of an existing Stage instance. +// +// It requires the user to be a moderator of the Stage channel. +func (c *Client) UpdateStageInstance( + channelID discord.ChannelID, data UpdateStageInstanceData) error { + + return c.FastRequest( + "PATCH", + EndpointStageInstances+channelID.String(), + httputil.WithJSONBody(data), + ) +} + +func (c *Client) DeleteStageInstance(channelID discord.ChannelID) error { + return c.FastRequest("DELETE", EndpointStageInstances+channelID.String()) +} diff --git a/discord/channel.go b/discord/channel.go index 53f53c1..3dbf185 100644 --- a/discord/channel.go +++ b/discord/channel.go @@ -8,6 +8,8 @@ import ( "github.com/diamondburned/arikawa/v2/utils/json" ) +// Channel represents a guild or DM channel within Discord. +// // https://discord.com/developers/docs/resources/channel#channel-object type Channel struct { // ID is the id of this channel. @@ -162,6 +164,20 @@ const ( // GuildStore is a channel in which game developers can sell their game on // Discord. GuildStore + _ + _ + _ + // GuildNewsThread is a temporary sub-channel within a GUILD_NEWS channel + GuildNewsThread + // GuildPublicThread is a temporary sub-channel within a GUILD_TEXT + // channel. + GuildPublicThread + // GuildPrivateThread isa temporary sub-channel within a GUILD_TEXT channel + // that is only viewable by those invited and those with the MANAGE_THREADS + // permission. + GuildPrivateThread + // GuildStageVoice is a voice channel for hosting events with an audience. + GuildStageVoice ) // https://discord.com/developers/docs/resources/channel#overwrite-object diff --git a/discord/snowflake.go b/discord/snowflake.go index 151eef7..466044b 100644 --- a/discord/snowflake.go +++ b/discord/snowflake.go @@ -250,6 +250,20 @@ func (s RoleID) PID() uint8 { return Snowflake(s).PID() } func (s RoleID) Increment() uint16 { return Snowflake(s).Increment() } func (s RoleID) Mention() string { return "<@&" + s.String() + ">" } +type StageID Snowflake + +const NullStageID = StageID(NullSnowflake) + +func (s StageID) MarshalJSON() ([]byte, error) { return Snowflake(s).MarshalJSON() } +func (s *StageID) UnmarshalJSON(v []byte) error { return (*Snowflake)(s).UnmarshalJSON(v) } +func (s StageID) String() string { return Snowflake(s).String() } +func (s StageID) IsValid() bool { return Snowflake(s).IsValid() } +func (s StageID) IsNull() bool { return Snowflake(s).IsNull() } +func (s StageID) Time() time.Time { return Snowflake(s).Time() } +func (s StageID) Worker() uint8 { return Snowflake(s).Worker() } +func (s StageID) PID() uint8 { return Snowflake(s).PID() } +func (s StageID) Increment() uint16 { return Snowflake(s).Increment() } + type StickerID Snowflake const NullStickerID = StickerID(NullSnowflake) diff --git a/discord/stage.go b/discord/stage.go new file mode 100644 index 0000000..0008247 --- /dev/null +++ b/discord/stage.go @@ -0,0 +1,31 @@ +package discord + +// A StageInstance holds information about a live stage instance. +// +// https://discord.com/developers/docs/resources/stage-instance#stage-instance-object +type StageInstance struct { + // ID is the id of this Stage instance. + ID StageID `json:"id"` + // GuildID is the guild id of the associated Stage channel. + GuildID GuildID `json:"guild_id"` + // ChannelID is the id of the associated Stage channel. + ChannelID ChannelID `json:"channel_id"` + // Topic is the topic of the Stage instance (1-120 characters). + Topic string `json:"topic"` + // PrivacyLevel is the privacy level of the Stage instance. + PrivacyLevel PrivacyLevel `json:"privacy_level"` + // NotDiscoverable defines whether or not Stage discovery is disabled. + NotDiscoverable bool `json:"discoverable_disabled"` +} + +type PrivacyLevel int + +// https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-privacy-level +const ( + // PublicStage is used if a StageInstance instance is visible publicly, such as on + // StageInstance discovery. + PublicStage PrivacyLevel = iota + 1 + // GuildOnlyStage is used if a StageInstance instance is visible to only guild + // members. + GuildOnlyStage +)