Skip to content

Commit

Permalink
support sending messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Feb 17, 2024
1 parent 7b3040c commit a17b8da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
31 changes: 28 additions & 3 deletions internal/helixclient/chat.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
package helixclient

import "github.com/nicklaw5/helix/v2"
import (
"context"

func (c *HelixClient) SendChatMessage(params *helix.SendChatMessageParams) (*helix.ChatMessageResponse, error) {
return c.Client.SendChatMessage(params)
"github.com/carlmjohnson/requests"
"github.com/nicklaw5/helix/v2"
)

type SendChatMessageResponse struct {
Data []struct {
MessageID string `json:"message_id"`
IsSent bool `json:"is_sent"`
} `json:"data"`
}

func (c *HelixClient) SendChatMessage(params *helix.SendChatMessageParams) (*SendChatMessageResponse, error) {
var resp SendChatMessageResponse

err := requests.
URL(TWITCH_API).
BodyJSON(params).
Bearer(c.AppAccessToken.AccessToken).
Header("Client-Id", c.clientID).
ContentType("application/json").
Path("/helix/chat/messages").
ToJSON(&resp).
Post().
Fetch(context.Background())

return &resp, err
}
4 changes: 2 additions & 2 deletions internal/helixclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Client interface {
SetUserAccessToken(token string)
ValidateToken(accessToken string) (bool, *helix.ValidateTokenResponse, error)
RequestUserAccessToken(code string) (*helix.UserAccessTokenResponse, error)
SendChatMessage(params *helix.SendChatMessageParams) (*helix.ChatMessageResponse, error)
SendChatMessage(params *helix.SendChatMessageParams) (*SendChatMessageResponse, error)
}

// Client wrapper for helix
Expand Down Expand Up @@ -65,7 +65,7 @@ func init() {

const TWITCH_API = "https://api.twitch.tv/"

var scopes = []string{"channel:read:redemptions", "channel:manage:redemptions", "channel:read:predictions", "channel:manage:predictions moderation:read channel:bot user:write:chat"}
var scopes = []string{"channel:read:redemptions", "channel:manage:redemptions", "channel:read:predictions", "channel:manage:predictions moderation:read channel:bot user:write:chat user:bot"}

// NewClient Create helix client
func NewClient(cfg *config.Config, db store.Store) *HelixClient {
Expand Down
2 changes: 1 addition & 1 deletion internal/helixclient/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ func (m *MockHelixClient) RequestUserAccessToken(code string) (*helix.UserAccess
return nil, nil
}

func (m *MockHelixClient) SendChatMessage(params *helix.SendChatMessageParams) (*helix.ChatMessageResponse, error) {
func (m *MockHelixClient) SendChatMessage(params *helix.SendChatMessageParams) (*SendChatMessageResponse, error) {
return nil, nil
}
13 changes: 0 additions & 13 deletions web/src/components/Bot/Bot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ export function Bot() {
<Toggle checked={!!botConfig?.JoinBot} onChange={handlePredictionCommandsChange} />
</div>
</div>
{isDev && <div className={"bg-gray-800 rounded shadow relative p-4 mt-4 " + (loadingUserConfig ? "animate-pulse pointer-events-none" : "")}>
<div className="flex items-start justify-between">
<div>
<h3 className="font-bold text-xl">Media Commands</h3>
<div className="p-2 text-gray-200 mx-0 px-0">
<ul className="list-disc pl-6 font-mono mt-2">
<li>!sr {"<youtube link>"}</li>
</ul>
</div>
</div>
<Toggle checked={!!botConfig?.MediaCommands} onChange={handleMediaCommandsChange} />
</div>
</div>}
</div >;
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/factory/createLoginUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function createLoginUrl(apiBaseUrl: string, twitchClientId: string): URL
url.searchParams.set("client_id", twitchClientId);
url.searchParams.set("redirect_uri", apiBaseUrl + "/api/callback");
url.searchParams.set("response_type", "code");
url.searchParams.set("scope", "channel:read:redemptions channel:manage:redemptions channel:read:predictions channel:manage:predictions moderation:read channel:bot user:write:chat");
url.searchParams.set("scope", "channel:read:redemptions channel:manage:redemptions channel:read:predictions channel:manage:predictions moderation:read channel:bot user:write:chat user:bot");

return url;
}

0 comments on commit a17b8da

Please sign in to comment.