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"
|
|
|
|
|
"net/url"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-02-28 10:30:20 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetChannelChatBadgesResponse struct {
|
|
|
|
|
// The list of chat badges. The list is sorted in ascending order by set_id, and within a set, the list is sorted in ascending order by id.
|
|
|
|
|
Data []Badge `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the broadcaster’s list of custom chat badges. The list is empty if the broadcaster hasn’t created custom chat badges.
|
|
|
|
|
// For information about custom badges,
|
|
|
|
|
// see subscriber badges: https://help.twitch.tv/s/article/subscriber-badge-guide
|
|
|
|
|
// and Bits badges: https://help.twitch.tv/s/article/custom-bit-badges-guide.
|
|
|
|
|
//
|
|
|
|
|
// Requires an app access token or user access token.
|
|
|
|
|
func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) (*GetChannelChatBadgesResponse, error) {
|
2024-03-07 20:52:42 -05:00
|
|
|
|
v := url.Values{"broadcaster_id": {broadcasterID}}
|
2024-02-28 10:30:20 -05:00
|
|
|
|
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/badges", 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 channel chat badges (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 10:30:20 -05:00
|
|
|
|
var data GetChannelChatBadgesResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|