go-twitch/api/moderation/add_channel_moderator.go

46 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package moderation
import (
"context"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type AddChannelModeratorParams struct {
// The ID of the broadcaster that owns the chat room. This ID must match the user ID in the access token.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the user to add as a moderator in the broadcasters chat room.
UserID string `url:"user_id"`
}
// Adds a moderator to the broadcasters chat room.
//
// Rate Limits: The broadcaster may add a maximum of 10 moderators within a 10-second window.
//
// Requires a user access token that includes the channel:manage:moderators scope.
func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannelModeratorParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/moderators", v), nil)
if err != nil {
return err
}
res, err := m.client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return fmt.Errorf("failed to add channel moderator (%d)", res.StatusCode)
}
return nil
}