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"
|
|
|
|
|
|
|
|
|
|
"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 DeleteChatMessagesParams struct {
|
|
|
|
|
// The ID of the broadcaster that owns the chat room to remove messages from.
|
|
|
|
|
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"`
|
|
|
|
|
|
|
|
|
|
// The ID of the message to remove. The id tag in the PRIVMSG tag contains the message’s ID. Restrictions:
|
|
|
|
|
//
|
|
|
|
|
// - The message must have been created within the last 6 hours.
|
|
|
|
|
//
|
|
|
|
|
// - The message must not belong to the broadcaster.
|
|
|
|
|
//
|
|
|
|
|
// - The message must not belong to another moderator.
|
|
|
|
|
//
|
|
|
|
|
// If not specified, the request removes all messages in the broadcaster’s chat room.
|
|
|
|
|
MessageID *string `url:"message_id,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Removes a single chat message or all chat messages from the broadcaster’s chat room.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the moderator:manage:chat_messages scope.
|
|
|
|
|
func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatMessagesParams) error {
|
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/chat", v), 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 delete chat messages (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
|
return nil
|
|
|
|
|
}
|