go-twitch/api/moderation/remove_channel_moderator.go

47 lines
1.3 KiB
Go
Raw Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"fmt"
2024-03-03 15:14:59 -05:00
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type RemoveChannelModeratorParams 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 remove as a moderator from the broadcasters chat room.
UserID string `url:"user_id"`
}
// Removes a moderator from the broadcasters chat room.
//
// Rate Limits: The broadcaster may remove 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) RemoveChannelModerator(ctx context.Context, params *RemoveChannelModeratorParams) error {
v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.String(), 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 remove channel moderator (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
return nil
}