116 lines
3.3 KiB
Go
116 lines
3.3 KiB
Go
package moderation
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
"time"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"go.fifitido.net/twitch/api/endpoint"
|
||
)
|
||
|
||
type ResolveUnbanRequestsParams struct {
|
||
// The ID of the broadcaster whose chat room the user is banned from chatting in.
|
||
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 unban request.
|
||
UnbanRequestID string `url:"unban_request_id"`
|
||
|
||
// Resolution status. Accepted values:
|
||
// approved or denied
|
||
Status string `url:"status"`
|
||
|
||
// Message supplied by the unban request resolver. The message is limited to a maximum of 500 characters.
|
||
ResolutionText *string `url:"resolution_text,omitempty"`
|
||
}
|
||
|
||
type ResolveUnbanRequestsResponse struct {
|
||
// An array containing the information about the resolved unban request.
|
||
Data []ResolveUnbanRequestsResponseData `json:"data"`
|
||
}
|
||
|
||
type ResolveUnbanRequestsResponseData struct {
|
||
// Unban request ID.
|
||
ID string `json:"id"`
|
||
|
||
// User ID of broadcaster whose channel is receiving the unban request.
|
||
BroadcasterID string `json:"broadcaster_id"`
|
||
|
||
// The broadcaster's display name.
|
||
BroadcasterName string `json:"broadcaster_name"`
|
||
|
||
// The broadcaster's login name.
|
||
BroadcasterLogin string `json:"broadcaster_login"`
|
||
|
||
// User ID of moderator who approved/denied the request.
|
||
ModeratorID string `json:"moderator_id"`
|
||
|
||
// The moderator's login name
|
||
ModeratorLogin string `json:"moderator_login"`
|
||
|
||
// The moderator's display name
|
||
ModeratorName string `json:"moderator_name"`
|
||
|
||
// User ID of the requestor who is asking for an unban.
|
||
UserID string `json:"user_id"`
|
||
|
||
// The user's login name.
|
||
UserLogin string `json:"user_login"`
|
||
|
||
// The user's display name.
|
||
UserName string `json:"user_name"`
|
||
|
||
// Text of the request from the requesting user.
|
||
Text string `json:"text"`
|
||
|
||
// Status of the request. One of:
|
||
// approved or denied
|
||
Status string `json:"status"`
|
||
|
||
// Timestamp of when the unban request was created.
|
||
CreatedAt time.Time `json:"created_at"`
|
||
|
||
// Timestamp of when moderator/broadcaster approved or denied the request.
|
||
ResolvedAt time.Time `json:"resolved_at"`
|
||
|
||
// Text input by the resolver (moderator) of the unban. request
|
||
ResolutionText string `json:"resolution_text"`
|
||
}
|
||
|
||
// Resolves an unban request by approving or denying it.
|
||
//
|
||
// Requires a user access token that includes the moderator:manage:unban_requests scope.
|
||
// Query parameter moderator_id must match the user_id in the user access token.
|
||
func (m *Moderation) ResolveUnbanRequests(ctx context.Context, params *ResolveUnbanRequestsParams) (*ResolveUnbanRequestsResponse, error) {
|
||
v, _ := query.Values(params)
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Make(m.baseUrl, "moderation/unban_requests", v), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := m.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 resolve unban requests (%d)", res.StatusCode)
|
||
}
|
||
|
||
var data ResolveUnbanRequestsResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|