package bits import ( "context" "encoding/json" "fmt" "net/http" "net/url" "time" ) type GetCheermotesResponse struct { // The list of Cheermotes. The list is in ascending order by the order field’s value. Data []Cheermote `json:"data"` } type Cheermote struct { // The name portion of the Cheermote string that you use in chat to cheer Bits. // The full Cheermote string is the concatenation of {prefix} + {number of Bits}. // For example, if the prefix is “Cheer” and you want to cheer 100 Bits, the full Cheermote string is Cheer100. // When the Cheermote string is entered in chat, Twitch converts it to the image associated with the Bits tier that was cheered. Prefix string `json:"prefix"` // A list of tier levels that the Cheermote supports. // Each tier identifies the range of Bits that you can cheer at that tier level and an image that graphically identifies the tier level. Tiers []CheermoteTier `json:"tiers"` // The type of Cheermote. Type CheermoteType `json:"type"` // The order that the Cheermotes are shown in the Bits card. The numbers may not be consecutive. For example, the numbers may jump from 1 to 7 to 13. // The order numbers are unique within a Cheermote type (for example, global_first_party) but may not be unique amongst all Cheermotes in the response. Order int `json:"order"` // The date and time, in RFC3339 format, when this Cheermote was last updated. LastUpdated time.Time `json:"last_updated"` // A Boolean value that indicates whether this Cheermote provides a charitable contribution match during charity campaigns. IsCharitable bool `json:"is_charitable"` } type CheermoteTier struct { // The minimum number of Bits that you must cheer at this tier level. // The maximum number of Bits that you can cheer at this level is determined by the required minimum Bits of the next tier level minus 1. // For example, if min_bits is 1 and min_bits for the next tier is 100, the Bits range for this tier level is 1 through 99. // The minimum Bits value of the last tier is the maximum number of Bits you can cheer using this Cheermote. For example, 10000. MinBits int `json:"min_bits"` // The tier level. Possible tiers are: // // 1, 100, 500, 1000, 5000, 10000, 100000 ID string `json:"id"` // The hex code of the color associated with this tier level (for example, #979797). Color string `json:"color"` // The animated and static image sets for the Cheermote. The dictionary of images is organized by theme, format, and size. // The theme keys are dark and light. Each theme is a dictionary of formats: animated and static. // Each format is a dictionary of sizes: 1, 1.5, 2, 3, and 4. The value of each size contains the URL to the image. Images map[string]CheermoteImage `json:"images"` // A Boolean value that determines whether users can cheer at this tier level. CanCheer bool `json:"can_cheer"` // A Boolean value that determines whether this tier level is shown in the Bits card. Is true if this tier level is shown in the Bits card. ShowInBitsCard bool `json:"show_in_bits_card"` } type CheermoteImage struct { Animated *CheermoteImageSizes `json:"animated"` Static *CheermoteImageSizes `json:"static"` } type CheermoteImageSizes struct { One CheermoteImage `json:"1"` One5 CheermoteImage `json:"1.5"` Two CheermoteImage `json:"2"` Three CheermoteImage `json:"3"` Four CheermoteImage `json:"4"` } // Gets a list of Cheermotes that users can use to cheer Bits in any Bits-enabled channel’s chat room. Cheermotes are animated emotes that viewers can assign Bits to. // // Requires an app access token or user access token. func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetCheermotesResponse, error) { endpoint := b.baseUrl.ResolveReference(&url.URL{Path: "bits/cheermotes", RawQuery: "broadcaster_id=" + broadcasterID}) req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil) if err != nil { return nil, err } res, err := b.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 cheermotes (%d)", res.StatusCode) } var data GetCheermotesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } return &data, nil }