2024-02-28 10:30:20 -05:00
|
|
|
|
package chat
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-02-28 10:30:20 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
"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 broadcaster’s 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 broadcaster’s 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)
|
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
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()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
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
|
|
|
|
|
}
|