package moderation import ( "context" "encoding/json" "fmt" "io" "net/http" "github.com/google/go-querystring/query" "go.fifitido.net/twitch/api/endpoint" ) type UpdateAutoModSettingsParams struct { // The ID of the broadcaster whose AutoMod settings you want to update. 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"` } // Because PUT is an overwrite operation, you must include all the fields that you want set after the operation completes. // Typically, you’ll send a GET request, update the fields you want to change, and pass that object in the PUT request. // // You may set either overall_level or the individual settings like aggression, but not both. // // Setting overall_level applies default values to the individual settings. // However, setting overall_level to 4 does not necessarily mean that it applies 4 to all the individual settings. // Instead, it applies a set of recommended defaults to the rest of the settings. // For example, if you set overall_level to 2, Twitch provides some filtering on discrimination and sexual content, // but more filtering on hostility (see the first example response). // // If overall_level is currently set and you update swearing to 3, overall_level will be set to null and all settings other than swearing will be set to 0. // The same is true if individual settings are set and you update overall_level to 3 — all the individual settings are updated to reflect the default level. // // Note that if you set all the individual settings to values that match what overall_level would have set them to, // Twitch changes AutoMod to use the default AutoMod level instead of using the individual settings. // // Valid values for all levels are from 0 (no filtering) through 4 (most aggressive filtering). // These levels affect how aggressively AutoMod holds back messages for moderators to review before they appear in chat or are denied (not shown). type UpdateAutoModSettingsRequest struct { // The Automod level for hostility involving aggression. Aggression int `json:"aggression"` // The Automod level for hostility involving name calling or insults. Bullying int `json:"bullying"` // The Automod level for discrimination against disability. Disability int `json:"disability"` // The Automod level for discrimination against women. Misogyny int `json:"misogyny"` // The default AutoMod level for the broadcaster. OverallLevel int `json:"overall_level"` // The Automod level for discrimination based on sexuality, sex, or gender. RaceEthnicityOrReligion int `json:"race_ethnicity_or_religion"` // The Automod level for sexual content. SexBasedTerms int `json:"sex_based_terms"` // The Automod level for discrimination against sexuality, sex, or gender. SexualitySexOrGender int `json:"sexuality_sex_or_gender"` // The Automod level for profanity. Swearing int `json:"swearing"` } type UpdateAutoModSettingsResponse struct { // The list of AutoMod settings. The list contains a single object that contains all the AutoMod settings. Data []AutoModSettings `json:"data"` } // Updates 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:manage:automod_settings scope. func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAutoModSettingsParams, body *UpdateAutoModSettingsRequest) (*UpdateAutoModSettingsResponse, error) { v, _ := query.Values(params) 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.MethodPut, endpoint.Make(m.baseUrl, "moderation/automod/settings", v), r) if err != nil { return nil, err } res, err := m.client.Do(req) if err != nil { return nil, err } defer res.Body.Close() statusOK := res.StatusCode >= 200 && res.StatusCode < 300 if !statusOK { return nil, fmt.Errorf("failed to update automod settings (%d)", res.StatusCode) } var data UpdateAutoModSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } return &data, nil }