go-twitch/api/moderation/check_automod_status.go

80 lines
2.9 KiB
Go

package moderation
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
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 (c *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID string, params *CheckAutoModStatusRequest) (*CheckAutoModStatusResponse, error) {
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "modetation/enforcements/status", RawQuery: url.Values{"broadcaster_id": {broadcasterID}}.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.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 check automod status (%d)", res.StatusCode)
}
var data CheckAutoModStatusResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}