go-twitch/api/moderation/update_shield_mode_status.go

70 lines
2.2 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 moderation
import (
"context"
"encoding/json"
"io"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type UpdateShieldModeStatusParams struct {
// The ID of the broadcaster whose Shield Mode you want to activate or deactivate.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the broadcaster or a user that is one of the broadcasters moderators. This ID must match the user ID in the access token.
ModeratorID string `url:"moderator_id"`
}
type UpdateShieldModeStatusRequest struct {
// A Boolean value that determines whether to activate Shield Mode. Set to true to activate Shield Mode; otherwise, false to deactivate Shield Mode.
IsActive bool `json:"is_active"`
}
type UpdateShieldModeStatusResponse struct {
// A list that contains a single object with the broadcasters updated Shield Mode status.
Data []ShieldModeStatus `json:"data"`
}
// Activates or deactivates the broadcasters Shield Mode.
//
// Twitchs Shield Mode feature is like a panic button that broadcasters can push to protect themselves from chat abuse coming from one or more accounts.
// When activated, Shield Mode applies the overrides that the broadcaster configured in the Twitch UX.
// If the broadcaster hasnt configured Shield Mode, it applies default overrides.
//
// Requires a user access token that includes the moderator:manage:shield_mode scope.
func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateShieldModeStatusParams) (*UpdateShieldModeStatusResponse, error) {
v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/shield_mode", RawQuery: v.Encode()})
r, w := io.Pipe()
go func() {
if err := json.NewEncoder(w).Encode(UpdateShieldModeStatusRequest{IsActive: true}); 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 := m.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data UpdateShieldModeStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}