go-twitch/api/moderation/unban_user.go

50 lines
1.3 KiB
Go
Raw Permalink 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"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-03-03 15:14:59 -05:00
)
type UnbanUserParams 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 broadcasters chat room.
// This ID must match the user ID in the user access token.
ModeratorID string `url:"moderator_id"`
// The ID of the user to remove the ban or timeout from.
UserID string `url:"user_id"`
}
// Removes the ban or timeout that was placed on the specified user.
//
// # To ban a user, see Ban user
//
// Requires a user access token that includes the moderator:manage:banned_users scope.
func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) error {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, endpoint.Make(m.baseUrl, "moderation/bans", v), nil)
2024-03-03 15:14:59 -05:00
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 unban user (%d)", res.StatusCode)
}
2024-03-03 15:14:59 -05:00
return nil
}