go-twitch/api/chat/get_emote_sets.go

122 lines
4.3 KiB
Go

package chat
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/endpoint"
)
type GetEmoteSetsParams struct {
// An ID that identifies the emote set to get. Include this parameter for each emote set you want to get.
// For example, emote_set_id=1234&emote_set_id=5678. You may specify a maximum of 25 IDs.
// The response contains only the IDs that were found and ignores duplicate IDs.
//
// To get emote set IDs, use the Get Channel Emotes API.
EmoteSetIDs []string `url:"emote_set_id,omitempty"`
}
type GetEmoteSetsResponse struct {
// The list of emotes found in the specified emote sets. The list is empty if none of the IDs were found.
// The list is in the same order as the set IDs specified in the request. Each set contains one or more emoticons.
Data []EmoteSetEmote `json:"data"`
// A templated URL. Use the values from the id, format, scale, and theme_mode fields to replace the like-named placeholder strings
// in the templated URL to create a CDN (content delivery network) URL that you use to fetch the emote.
// For information about what the template looks like and how to use it to fetch emotes.
// See Emote CDN URL format: https://dev.twitch.tv/docs/irc/emotes#cdn-template
// You should use this template instead of using the URLs in the images object.
Template string `json:"template"`
}
type EmoteSetEmote struct {
// An ID that identifies this emote.
ID string `json:"id"`
// The name of the emote. This is the name that viewers type in the chat window to get the emote to appear.
Name string `json:"name"`
// The image URLs for the emote. These image URLs always provide a static, non-animated emote image with a light background.
//
// NOTE: You should use the templated URL in the template field to fetch the image instead of using these URLs.
Images EmoteImages `json:"images"`
// The type of emote. The possible values are:
//
// bitstier — A custom Bits tier emote.
//
// follower — A custom follower emote.
//
// subscriptions — A custom subscriber emote.
EmoteType string `json:"emote_type"`
// An ID that identifies the emote set that the emote belongs to.
EmoteSetID string `json:"emote_set_id"`
// The ID of the broadcaster who owns the emote.
OwnerID string `json:"owner_id"`
// The formats that the emote is available in.
// For example, if the emote is available only as a static PNG, the array contains only static.
// But if the emote is available as a static PNG and an animated GIF, the array contains static and animated.
// The possible formats are:
//
// animated — An animated GIF is available for this emote.
//
// static — A static PNG file is available for this emote.
Formats []EmoteFormat `json:"format"`
// The sizes that the emote is available in.
// For example, if the emote is available in small and medium sizes, the array contains 1.0 and 2.0.
// Possible sizes are:
//
// 1.0 — A small version (28px x 28px) is available.
//
// 2.0 — A medium version (56px x 56px) is available.
//
// 3.0 — A large version (112px x 112px) is available.
Scales []EmoteScale `json:"scale"`
// The background themes that the emote is available in. Possible themes are:
//
// dark, light
ThemeMode []EmoteThemeMode `json:"theme_mode"`
}
// Gets emotes for one or more specified emote sets.
//
// An emote set groups emotes that have a similar context. For example, Twitch places all the subscriber emotes that a broadcaster uploads for their channel in the same emote set.
//
// Learn More: https://dev.twitch.tv/docs/irc/emotes
//
// Requires an app access token or user access token.
func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*GetEmoteSetsResponse, error) {
v, _ := query.Values(params)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "chat/emotes/set", v), nil)
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 emote sets (%d)", res.StatusCode)
}
var data GetEmoteSetsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}