go-twitch/api/chat/get_chat_settings.go

58 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type GetChatSettingsParams struct {
// The ID of the broadcaster whose chat settings you want to get.
BroadcasterID string `url:"broadcaster_id"`
// The ID of the broadcaster or one of the broadcasters moderators.
//
// This field is required only if you want to include the non_moderator_chat_delay and non_moderator_chat_delay_duration settings in the response.
//
// If you specify this field, this ID must match the user ID in the user access token.
ModeratorID *string `url:"moderator_id,omitempty"`
}
type GetChatSettingsResponse struct {
// The list of chat settings. The list contains a single object with all the settings.
Data []Settings `json:"data"`
}
// Gets the broadcasters chat settings.
//
// For an overview of chat settings,
// see Chat Commands for Broadcasters and Moderators: https://help.twitch.tv/s/article/chat-commands#AllMods
// and Moderator Preferences: https://help.twitch.tv/s/article/setting-up-moderation-for-your-twitch-channel#modpreferences
//
// Requires an app access token or user access token.
func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParams) (*GetChatSettingsResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/settings", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetChatSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}