diff --git a/.env.development b/.env.development index b5bc234..128e190 100644 --- a/.env.development +++ b/.env.development @@ -1,7 +1,7 @@ NEXT_PUBLIC_API_BASE_URL="http://localhost:3010" NEXT_PUBLIC_BASE_URL="http://localhost:3000" NEXT_PUBLIC_TWITCH_CLIENT_ID="7ex2fcx0zjznrb3o20gl10f53ury1j" -WEBHOOK_API_BASE_URL="https://gempbot.bore.services" +WEBHOOK_API_BASE_URL="https://gempbot.loca.lt" TWITCH_USERNAME="gempbot" DSN="postgresql://postgres:postgres@localhost:5432" LISTEN_ADDRESS="127.0.0.1:3010" diff --git a/Makefile b/Makefile index 5c0fb29..4d1b9e3 100644 --- a/Makefile +++ b/Makefile @@ -45,4 +45,4 @@ run_docker: docker run --env-file=.env -p 3010:3010 gempbot tunnel: - bore -id gempbot -s bore.services -p 2200 -ls localhost -lp 3010 + npx localtunnel --port 3010 --subdomain gempbot \ No newline at end of file diff --git a/internal/helixclient/chat.go b/internal/helixclient/chat.go index e76faf1..ab341cb 100644 --- a/internal/helixclient/chat.go +++ b/internal/helixclient/chat.go @@ -1,9 +1,12 @@ package helixclient import ( - "context" + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" - "github.com/carlmjohnson/requests" "github.com/nicklaw5/helix/v2" ) @@ -15,24 +18,46 @@ type SendChatMessageResponse struct { } func (c *HelixClient) SendChatMessage(channelID string, message string) (*SendChatMessageResponse, error) { - var resp SendChatMessageResponse - params := helix.SendChatMessageParams{ BroadcasterID: channelID, Message: message, SenderID: c.botUserID, } - 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 + jsonParams, err := json.Marshal(params) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", fmt.Sprintf("%s/helix/chat/messages", TWITCH_API), bytes.NewBuffer(jsonParams)) + if err != nil { + return nil, err + } + + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.AppAccessToken.AccessToken)) + req.Header.Set("Client-Id", c.clientID) + req.Header.Set("Content-Type", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + if resp.StatusCode >= 300 { + return nil, fmt.Errorf("[%d] %s", resp.StatusCode, string(body)) + } + + var msgs SendChatMessageResponse + err = json.Unmarshal(body, &msgs) + if err != nil { + return nil, err + } + + return &msgs, nil }