go-twitch/api/moderation/get_banned_users.go

105 lines
3.6 KiB
Go
Raw Normal View History

2024-03-03 15:14:59 -05:00
package moderation
import (
"context"
"encoding/json"
"net/http"
"net/url"
"time"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetBannedUsersParams struct {
// The ID of the broadcaster whose list of banned users 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 user 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 those users that were banned or put in a timeout.
// The list is returned in the same order that you specified the IDs.
UserID []string `url:"user_id,omitempty"`
2024-03-03 15:14:59 -05:00
// 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"`
2024-03-03 15:14:59 -05:00
// The cursor used to get the next page of results. The Pagination object in the response contains the cursors value.
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
After *types.Cursor `url:"after,omitempty"`
2024-03-03 15:14:59 -05:00
// The cursor used to get the previous page of results. The Pagination object in the response contains the cursors value.
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
Before *types.Cursor `url:"before,omitempty"`
2024-03-03 15:14:59 -05:00
}
type GetBannedUsersResponse struct {
// The list of banned users. The list contains a single object that contains all the banned users.
Data []GetBannedUsersResponseData `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 GetBannedUsersResponseData struct {
// The ID of the banned user.
UserID string `json:"user_id"`
// The banned users login name.
UserLogin string `json:"user_login"`
// The banned users display name.
UserName string `json:"user_name"`
// The UTC date and time (in RFC3339 format) of when the timeout expires, or an empty string if the user is permanently banned.
ExpiresAt time.Time `json:"expires_at"`
// The UTC date and time (in RFC3339 format) of when the user was banned.
CreatedAt time.Time `json:"created_at"`
// The reason the user was banned or put in a timeout if the moderator provided one.
Reason string `json:"reason"`
// The ID of the moderator that banned the user or put them in a timeout.
ModeratorID string `json:"moderator_id"`
// The moderators login name.
ModeratorLogin string `json:"moderator_login"`
// The moderators display name.
ModeratorName string `json:"moderator_name"`
}
// Gets all users that the broadcaster banned or put in a timeout.
//
// Requires a user access token that includes the moderation:read or moderator:manage:banned_users scope.
func (m *Moderation) GetBannedUsers(ctx context.Context, params *GetBannedUsersParams) (*GetBannedUsersResponse, error) {
v, _ := query.Values(params)
endpoint := m.baseUrl.ResolveReference(&url.URL{Path: "moderation/banned", 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 GetBannedUsersResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}