2024-03-03 15:14:59 -05:00
|
|
|
|
package moderation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetAutoModSettingsParams struct {
|
|
|
|
|
// The ID of the broadcaster whose AutoMod settings you want to get.
|
|
|
|
|
BroadcasterID string `url:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The ID of the broadcaster or a user that has permission to moderate the broadcaster’s chat room.
|
|
|
|
|
// This ID must match the user ID in the user access token.
|
|
|
|
|
ModeratorID string `url:"moderator_id"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetAutoModSettingsResponse struct {
|
|
|
|
|
// The list of AutoMod settings. The list contains a single object that contains all the AutoMod settings.
|
|
|
|
|
Data []AutoModSettings `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the broadcaster’s AutoMod settings.
|
|
|
|
|
// The settings are used to automatically block inappropriate or harassing messages from appearing in the broadcaster’s chat room.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the moderator:read:automod_settings scope.
|
|
|
|
|
func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModSettingsParams) (*GetAutoModSettingsResponse, error) {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), nil)
|
2024-03-03 15:14:59 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := m.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get automod settings (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
|
var data GetAutoModSettingsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|