2024-03-03 15:14:59 -05:00
|
|
|
package moderation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-03-07 19:41:05 -05:00
|
|
|
"fmt"
|
2024-03-03 15:14:59 -05:00
|
|
|
"net/http"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 15:14:59 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type AutoModAction string
|
|
|
|
|
|
|
|
const (
|
|
|
|
AutoModActionAllow AutoModAction = "ALLOW"
|
|
|
|
AutoModActionDeny AutoModAction = "DENY"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ManageHeldAutoModMessagesRequest struct {
|
|
|
|
// The moderator who is approving or denying the held message. This ID must match the user ID in the access token.
|
|
|
|
UserID string `url:"user_id"`
|
|
|
|
|
|
|
|
// The ID of the message to allow or deny.
|
|
|
|
MsgID string `url:"msg_id"`
|
|
|
|
|
|
|
|
// The action to take for the message.
|
|
|
|
Action AutoModAction `url:"action"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow or deny the message that AutoMod flagged for review.
|
|
|
|
// For information about AutoMod, see How to Use AutoMod: https://help.twitch.tv/s/article/how-to-use-automod
|
|
|
|
//
|
|
|
|
// To get messages that AutoMod is holding for review, subscribe to the automod-queue.<moderator_id>.<channel_id> topic using PubSub.
|
|
|
|
// PubSub sends a notification to your app when AutoMod holds a message for review.
|
|
|
|
//
|
|
|
|
// Requires a user access token that includes the moderator:manage:automod scope.
|
|
|
|
func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *ManageHeldAutoModMessagesRequest) error {
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/automod/message"), nil)
|
2024-03-03 15:14:59 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := m.client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
if !statusOK {
|
|
|
|
return fmt.Errorf("failed to manage held AutoMod messages (%d)", res.StatusCode)
|
|
|
|
}
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
return nil
|
|
|
|
}
|