Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support of Stage Instance RestAPI and Events #1158

Merged
merged 15 commits into from Apr 14, 2022
Merged
7 changes: 4 additions & 3 deletions examples/stage_instance/main.go
Expand Up @@ -32,7 +32,7 @@ func main() {
defer s.Close()

// Create a new Stage instance on the previous channel
si, err := s.StageInstanceCreate(&discordgo.StageInstanceData{
si, err := s.StageInstanceCreate(&discordgo.StageInstanceParams{
ChannelID: *StageChannelID,
Topic: "Amazing topic",
PrivacyLevel: discordgo.StageInstancePrivacyLevelGuildOnly,
Expand All @@ -44,8 +44,9 @@ func main() {
log.Printf("Stage Instance %s has been successfully created", si.Topic)

// Edit the stage instance with a new Topic
si.Topic = "New amazing topic"
si, err = s.StageInstanceEdit(*StageChannelID, si)
si, err = s.StageInstanceEdit(*StageChannelID, &discordgo.StageInstanceParams{
Topic: "New amazing topic",
})
if err != nil {
log.Fatalf("Cannot edit stage instance: %v", err)
}
Expand Down
12 changes: 2 additions & 10 deletions restapi.go
Expand Up @@ -2880,7 +2880,7 @@ func (s *Session) FollowupMessageDelete(appID string, interaction *Interaction,

// StageInstanceCreate will creates a new Stage instance associated to a Stage channel.
// Returns that Stage instance created
func (s *Session) StageInstanceCreate(data *StageInstanceData) (si *StageInstance, err error) {
func (s *Session) StageInstanceCreate(data *StageInstanceParams) (si *StageInstance, err error) {
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
body, err := s.RequestWithBucketID("POST", EndpointStageInstances, data, EndpointStageInstances)
if err != nil {
return
Expand All @@ -2906,15 +2906,7 @@ func (s *Session) StageInstance(channelID string) (si *StageInstance, err error)
// channelID : The ID of the Stage channel
// topic : The new topic of the Stage instance (1-120 characters). Set empty to keep the current topic.
// privacyLevel : The new privacy level of the Stage instance. Set nil to keep the current privacy level.
42atomys marked this conversation as resolved.
Show resolved Hide resolved
func (s *Session) StageInstanceEdit(channelID string, instance *StageInstance) (si *StageInstance, err error) {
data := struct {
Topic string `json:"topic,omitempty"`
// PrivacyLevel of the Stage instance (default GUILD_ONLY)
PrivacyLevel *StageInstancePrivacyLevel `json:"privacy_level,omitempty"`
}{
Topic: instance.Topic,
PrivacyLevel: &instance.PrivacyLevel,
}
func (s *Session) StageInstanceEdit(channelID string, data *StageInstanceParams) (si *StageInstance, err error) {
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved
FedorLap2006 marked this conversation as resolved.
Show resolved Hide resolved

body, err := s.RequestWithBucketID("PATCH", EndpointStageInstance(channelID), data, EndpointStageInstance(channelID))
if err != nil {
Expand Down
15 changes: 4 additions & 11 deletions structs.go
Expand Up @@ -1776,10 +1776,11 @@ type StageInstance struct {
GuildScheduledEventID string `json:"guild_scheduled_event_id"`
}

// StageInstanceData is provided to StageInstanceCreate
type StageInstanceData struct {
// StageInstanceParams represents the parameters that allow to make a request via
// StageInstanceCreate and StageInstanceEdit
42atomys marked this conversation as resolved.
Show resolved Hide resolved
type StageInstanceParams struct {
// ChannelID represents the id of the Stage channel
ChannelID string `json:"channel_id"`
ChannelID string `json:"channel_id,omitempty"`
// Topic of the Stage instance (1-120 characters)
Topic string `json:"topic"`
42atomys marked this conversation as resolved.
Show resolved Hide resolved
// PrivacyLevel of the Stage instance (default GUILD_ONLY)
Expand All @@ -1788,14 +1789,6 @@ type StageInstanceData struct {
SendStartNotification bool `json:"send_start_notification,omitempty"`
}

// StageInstanceEditData is provided to StageInstanceEdit
type StageInstanceEditData struct {
// Topic of the Stage instance (1-120 characters)
Topic string `json:"topic"`
// PrivacyLevel of the Stage instance (default GUILD_ONLY)
PrivacyLevel StageInstancePrivacyLevel `json:"privacy_level,omitempty"`
}

// StageInstancePrivacyLevel The privacy level of the Stage instance
42atomys marked this conversation as resolved.
Show resolved Hide resolved
// https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-privacy-level
type StageInstancePrivacyLevel int
Expand Down