83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package moderation
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"net/http"
|
||
"net/url"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"go.fifitido.net/twitch/api/types"
|
||
)
|
||
|
||
type GetModeratorsParams struct {
|
||
// The ID of the broadcaster whose list of moderators you want to get. This ID must match the user ID in the access token.
|
||
BroadcasterID string `url:"broadcaster_id"`
|
||
|
||
// A list of user IDs used to filter the results.
|
||
// To specify more than one ID, include this parameter for each moderator you want to get.
|
||
// For example, user_id=1234&user_id=5678.
|
||
// You may specify a maximum of 100 IDs.
|
||
//
|
||
// The returned list includes only the users from the list who are moderators in the broadcaster’s channel.
|
||
// The list is returned in the same order as you specified the IDs.
|
||
UserID []string `url:"user_id,omitempty"`
|
||
|
||
// The maximum number of items to return per page in the response.
|
||
// The minimum page size is 1 item per page and the maximum is 100 items per page.
|
||
// The default is 20.
|
||
First *int `url:"first,omitempty"`
|
||
|
||
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||
After *types.Cursor `url:"after,omitempty"`
|
||
}
|
||
|
||
type GetModeratorsResponse struct {
|
||
// The list of moderators. The list contains a single object that contains all the moderators.
|
||
Data []GetModeratorsResponseData `json:"data"`
|
||
|
||
// Contains information about the pagination in the response.
|
||
// The object is empty if there are no more pages of results.
|
||
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
||
Pagination types.Pagination `json:"pagination"`
|
||
}
|
||
|
||
type GetModeratorsResponseData struct {
|
||
// The ID of the user that has permission to moderate the broadcaster’s channel.
|
||
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"`
|
||
}
|
||
|
||
// Gets all users allowed to moderate the broadcaster’s chat room.
|
||
//
|
||
// Requires a user access token that includes the moderation:read scope.
|
||
// If your app also adds and removes moderators, you can use the channel:manage:moderators scope instead.
|
||
func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsParams) (*GetModeratorsResponse, error) {
|
||
v, _ := query.Values(params)
|
||
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/moderators", RawQuery: v.Encode()})
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := m.client.Do(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer res.Body.Close()
|
||
|
||
var data GetModeratorsResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|