go-twitch/api/chat/get_user_chat_color.go

66 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"context"
"encoding/json"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
type GetUserChatColorParams struct {
// The ID of the user whose username color you want to get.
// To specify more than one user, include the user_id parameter for each user to get.
// For example, &user_id=1234&user_id=5678. The maximum number of IDs that you may specify is 100.
//
// The API ignores duplicate IDs and IDs that werent found.
UserIDs []string `url:"user_id"`
}
type GetUserChatColorResponse struct {
// The list of users and the color code they use for their name.
Data []UserChatColor `json:"data"`
}
type UserChatColor struct {
// An ID that uniquely identifies the user.
UserID string `json:"user_id"`
// The users login name.
UserLogin string `json:"user_login"`
// The users display name.
UserName string `json:"user_name"`
// The Hex color code that the user uses in chat for their name.
// If the user hasnt specified a color in their settings, the string is empty.
Color string `json:"color"`
}
// Gets the color used for the users name in chat.
//
// Requires an app access token or user access token.
func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorParams) (*GetUserChatColorResponse, error) {
v, _ := query.Values(params)
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "chat/color", RawQuery: v.Encode()})
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
var data GetUserChatColorResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}