2024-03-03 15:14:59 -05:00
|
|
|
|
package moderation
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-03-03 15:14:59 -05:00
|
|
|
|
"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.
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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.
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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 cursor’s value.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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 cursor’s value.
|
|
|
|
|
// Read More: https://dev.twitch.tv/docs/api/guide#pagination
|
2024-03-05 22:29:23 -05:00
|
|
|
|
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 user’s login name.
|
|
|
|
|
UserLogin string `json:"user_login"`
|
|
|
|
|
|
|
|
|
|
// The banned user’s 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 moderator’s login name.
|
|
|
|
|
ModeratorLogin string `json:"moderator_login"`
|
|
|
|
|
|
|
|
|
|
// The moderator’s 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)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(m.baseUrl, "moderation/banned", v), nil)
|
2024-03-03 15:14:59 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := m.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get banned users (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-03 15:14:59 -05:00
|
|
|
|
var data GetBannedUsersResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|