[twitch] Implement AddChannelVIP, RemoveChannelVIP

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-12-05 18:58:10 +01:00
parent 29ce8820bf
commit f0dfea1728
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5

View file

@ -10,6 +10,29 @@ import (
"github.com/pkg/errors"
)
func (c *Client) AddChannelVIP(ctx context.Context, broadcasterName, userName string) error {
broadcaster, err := c.GetIDForUsername(broadcasterName)
if err != nil {
return errors.Wrap(err, "getting ID for broadcaster name")
}
userID, err := c.GetIDForUsername(userName)
if err != nil {
return errors.Wrap(err, "getting ID for user name")
}
return errors.Wrap(
c.request(clientRequestOpts{
AuthType: authTypeBearerToken,
Context: ctx,
Method: http.MethodPost,
OKStatus: http.StatusNoContent,
URL: fmt.Sprintf("https://api.twitch.tv/helix/channels/vips?broadcaster_id=%s&user_id=%s", broadcaster, userID),
}),
"executing request",
)
}
func (c *Client) ModifyChannelInformation(ctx context.Context, broadcasterName string, game, title *string) error {
if game == nil && title == nil {
return errors.New("netiher game nor title provided")
@ -83,3 +106,26 @@ func (c *Client) ModifyChannelInformation(ctx context.Context, broadcasterName s
"executing request",
)
}
func (c *Client) RemoveChannelVIP(ctx context.Context, broadcasterName, userName string) error {
broadcaster, err := c.GetIDForUsername(broadcasterName)
if err != nil {
return errors.Wrap(err, "getting ID for broadcaster name")
}
userID, err := c.GetIDForUsername(userName)
if err != nil {
return errors.Wrap(err, "getting ID for user name")
}
return errors.Wrap(
c.request(clientRequestOpts{
AuthType: authTypeBearerToken,
Context: ctx,
Method: http.MethodDelete,
OKStatus: http.StatusNoContent,
URL: fmt.Sprintf("https://api.twitch.tv/helix/channels/vips?broadcaster_id=%s&user_id=%s", broadcaster, userID),
}),
"executing request",
)
}