50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
|
package users
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
|
||
|
"github.com/google/go-querystring/query"
|
||
|
)
|
||
|
|
||
|
type BlockUserParams struct {
|
||
|
// The ID of the user to block. The API ignores the request if the broadcaster has already blocked the user.
|
||
|
TargetUserID string `url:"target_user_id"`
|
||
|
|
||
|
// The location where the harassment took place that is causing the brodcaster to block the user. Possible values are:
|
||
|
//
|
||
|
// chat, whisper
|
||
|
SourceContext *string `url:"source_context,omitempty"`
|
||
|
|
||
|
// The reason that the broadcaster is blocking the user. Possible values are:
|
||
|
//
|
||
|
// harassment, spam, other
|
||
|
Reason *string `url:"reason,omitempty"`
|
||
|
}
|
||
|
|
||
|
// Blocks the specified user from interacting with or having contact with the broadcaster.
|
||
|
// The user ID in the OAuth token identifies the broadcaster who is blocking the user.
|
||
|
//
|
||
|
// To learn more about blocking users,
|
||
|
// see Block Other Users on Twitch: https://help.twitch.tv/s/article/how-to-manage-harassment-in-chat?language=en_US#BlockWhispersandMessagesfromStrangers
|
||
|
//
|
||
|
// Requires a user access token that includes the user:manage:blocked_users scope.
|
||
|
func (u *Users) BlockUser(ctx context.Context, params *BlockUserParams) error {
|
||
|
v, _ := query.Values(params)
|
||
|
endpoint := u.baseUrl.ResolveReference(&url.URL{Path: "users/blocks", RawQuery: v.Encode()})
|
||
|
|
||
|
req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint.String(), nil)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
res, err := u.client.Do(req)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer res.Body.Close()
|
||
|
|
||
|
return nil
|
||
|
}
|