diff --git a/go.mod b/go.mod index b18cfc05..fa9ddd5e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ba1b8cb5..9f2f8de9 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/service/twitch/twitch.go b/service/twitch/twitch.go index 58d84256..f005fbad 100644 --- a/service/twitch/twitch.go +++ b/service/twitch/twitch.go @@ -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" @@ -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 }