Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev -> main #521

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
)

require (
github.com/bensch777/discord-webhook-golang v0.0.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/bensch777/discord-webhook-golang v0.0.6 h1:91BMU6vKgymAMfRwtXPMUrKX+SUoPPHTDJHTFA/1Kgk=
github.com/bensch777/discord-webhook-golang v0.0.6/go.mod h1:GcIorMZAZaHZyQJkjNoYKvZ6VpZo8XLib/eD51xN7Is=
github.com/bwmarrin/discordgo v0.28.1 h1:gXsuo2GBO7NbR6uqmrrBDplPUx2T3nzu775q/Rd1aG4=
github.com/bwmarrin/discordgo v0.28.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down
17 changes: 17 additions & 0 deletions service/twitch/twitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"strings"

discordwebhook "github.com/bensch777/discord-webhook-golang"
"github.com/senchabot-opensource/monorepo/model"
"golang.org/x/oauth2/clientcredentials"
"golang.org/x/oauth2/twitch"
Expand Down Expand Up @@ -149,6 +150,22 @@ func CheckMultipleTwitchStreamer(usernames []string) []model.TwitchStreamerData
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Println("[CheckMultipleTwitchStreamer] Twitch API request failed with status code:", resp.StatusCode)
if resp.StatusCode == http.StatusUnauthorized {
hook := discordwebhook.Hook{
Username: "Senchabot Webhook",
Avatar_url: "https://avatars.githubusercontent.com/u/94869947?v=4",
Content: "[CheckMultipleTwitchStreamer] Twitch API token is not authorized",
}

payload, err := json.Marshal(hook)
if err != nil {
log.Println("[CheckMultipleTwitchStreamer] Error while webhook json Marshal:", err.Error())
}
err = discordwebhook.ExecuteWebhook(os.Getenv("DISCORD_WEBHOOK_URL"), payload)
if err != nil {
log.Println("[CheckMultipleTwitchStreamer] ExecuteWebhook failed:", err.Error())
}
}
return nil
}

Expand Down
Loading