go-twitch/api/chat/get_chat_settings.go

63 lines
1.9 KiB
Go
Raw Permalink Normal View History

2024-02-28 10:30:20 -05:00
package chat
import (
"context"
"encoding/json"
"fmt"
2024-02-28 10:30:20 -05:00
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
2024-02-28 10:30:20 -05:00
)
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)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/settings", v), nil)
2024-02-28 10:30:20 -05:00
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
if !statusOK {
return nil, fmt.Errorf("failed to get chat settings (%d)", res.StatusCode)
}
2024-02-28 10:30:20 -05:00
var data GetChatSettingsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}