go-twitch/api/chat/update_chat_settings.go

126 lines
4.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type UpdateChatSettingsParams struct {
// The ID of the broadcaster whose chat settings you want to update.
BroadcasterID string `url:"broadcaster_id"`
// The ID of a user that has permission to moderate the broadcasters chat room, or the broadcasters ID if theyre making the update.
// This ID must match the user ID in the user access token.
ModeratorID string `url:"moderator_id"`
}
type UpdateChatSettingsRequest struct {
// A Boolean value that determines whether chat messages must contain only emotes.
//
// Set to true if only emotes are allowed; otherwise, false. The default is false.
EmoteMode *bool `json:"emote_mode"`
// A Boolean value that determines whether the broadcaster restricts the chat room to followers only.
//
// Set to true if the broadcaster restricts the chat room to followers only; otherwise, false. The default is true.
//
// To specify how long users must follow the broadcaster before being able to participate in the chat room, see the follower_mode_duration field.
FollowerMode *bool `json:"follower_mode"`
// The length of time, in minutes, that users must follow the broadcaster before being able to participate in the chat room.
// Set only if follower_mode is true.
// Possible values are: 0 (no restriction) through 129600 (3 months).
// The default is 0.
FollowerModeDuration *int `json:"follower_mode_duration"`
// A Boolean value that determines whether the broadcaster adds a short delay before chat messages appear in the chat room.
// This gives chat moderators and bots a chance to remove them before viewers can see the message.
//
// Set to true if the broadcaster applies a delay; otherwise, false.
// The default is false.
//
// To specify the length of the delay, see the non_moderator_chat_delay_duration field.
NonModeratorChatDelay *bool `json:"non_moderator_chat_delay"`
// The amount of time, in seconds, that messages are delayed before appearing in chat. Set only if non_moderator_chat_delay is true.
// Possible values are:
//
// 2 — 2 second delay (recommended)
//
// 4 — 4 second delay
//
// 6 — 6 second delay
NonModeratorChatDelayDuration *int `json:"non_moderator_chat_delay_duration"`
// A Boolean value that determines whether the broadcaster limits how often users in the chat room are allowed to send messages.
// Set to true if the broadcaster applies a wait period between messages; otherwise, false.
// The default is false.
//
// To specify the delay, see the slow_mode_wait_time field.
SlowMode bool `json:"slow_mode"`
// The amount of time, in seconds, that users must wait between sending messages.
// Set only if slow_mode is true.
//
// Possible values are: 3 (3 second delay) through 120 (2 minute delay). The default is 30 seconds.
SlowModeWaitTime *int `json:"slow_mode_wait_time"`
// A Boolean value that determines whether only users that subscribe to the broadcasters channel may talk in the chat room.
//
// Set to true if the broadcaster restricts the chat room to subscribers only; otherwise, false.
// The default is false.
SubscriberMode *bool `json:"subscriber_mode"`
// A Boolean value that determines whether the broadcaster requires users to post only unique messages in the chat room.
//
// Set to true if the broadcaster allows only unique messages; otherwise, false.
// The default is false.
UniqueChatMode *bool `json:"unique_chat_mode"`
}
type UpdateChatSettingsResponse struct {
// The list of chat settings. The list contains a single object with all the settings.
Data []Settings `json:"data"`
}
// Updates the broadcasters chat settings.
//
// Requires a user access token that includes the moderator:manage:chat_settings scope.
func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSettingsParams, body *UpdateChatSettingsRequest) (*UpdateChatSettingsResponse, error) {
v, _ := query.Values(body)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()})
r, w := io.Pipe()
go func() {
if err := json.NewEncoder(w).Encode(body); err != nil {
w.CloseWithError(err)
} else {
w.Close()
}
}()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, endpoint.String(), r)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data UpdateChatSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}