go-twitch/api/moderation/check_automod_status.go

82 lines
2.8 KiB
Go
Raw Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"encoding/json"
"fmt"
2024-03-03 15:14:59 -05:00
"net/http"
"net/url"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 15:14:59 -05:00
)
type CheckAutoModStatusRequest struct {
Data []CheckAutoModStatusRequestData `json:"data"`
}
type CheckAutoModStatusRequestData struct {
// A caller-defined ID used to correlate this message with the same message in the response.
MsgID string `json:"msg_id"`
// The message to check.
MsgText string `json:"msg_text"`
}
type CheckAutoModStatusResponse struct {
// The list of messages and whether Twitch would approve them for chat.
Data []CheckAutoModStatusResponseData `json:"data"`
}
type CheckAutoModStatusResponseData struct {
// The caller-defined ID passed in the request.
MsgID string `json:"msg_id"`
// A Boolean value that indicates whether Twitch would approve the message for chat or hold it for moderator review or block it from chat.
// Is true if Twitch would approve the message; otherwise, false if Twitch would hold the message for moderator review or block it from chat.
IsPermitted bool `json:"is_permitted"`
}
// Checks whether AutoMod would flag the specified message for review.
//
// AutoMod is a moderation tool that holds inappropriate or harassing chat messages for moderators to review. Moderators approve or deny the messages that AutoMod flags; only approved messages are released to chat. AutoMod detects misspellings and evasive language automatically. For information about AutoMod, see How to Use AutoMod.
//
// Rate Limits: Rates are limited per channel based on the account type rather than per access token.
//
// Account type | Limit per minute | Limit per hour
// ------------ | ---------------- | --------------
// Free | 1 | 10
// Normal | 5 | 50
// Affiliated | 10 | 100
// Partnered | 30 | 300
//
// The above limits are in addition to the standard Twitch API rate limits.
// The rate limit headers in the response represent the Twitch rate limits and not the above limits.
//
// Requires a user access token that includes the moderation:read scope.
func (m *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) {
v := url.Values{"broadcaster_id": {broadcasterID}}
2024-03-03 15:14:59 -05:00
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/enforcements/status", v), nil)
2024-03-03 15:14:59 -05:00
if err != nil {
return nil, err
}
res, err := m.client.Do(req)
2024-03-03 15:14:59 -05:00
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 check automod status (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
var data CheckAutoModStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}