NZCovidBot/internal/nzcovidbot/discord.go
Daniel Mason 86eef8cc8e
- Skip invalid webhooks
- Build cache based on row data instead of entire row
- Compare columns instead of entire row
- Removed commitHash check and instead just processes on succesfull git pull
- No more entire file dumps!
2021-09-03 14:18:47 +12:00

39 lines
671 B
Go

package nzcovidbot
import (
"log"
"strings"
"github.com/DisgoOrg/disgohook"
"github.com/DisgoOrg/disgohook/api"
)
// Slice of discord webhooks
var DiscordWebhooks []string
func postToDiscord(webhookString string, msg string) {
if webhookString == "" {
return
}
tokenParts := strings.Split(webhookString, "/")
len := len(tokenParts)
webhook, err := disgohook.NewWebhookClientByToken(nil, nil, tokenParts[len-2]+"/"+tokenParts[len-1])
if err != nil {
log.Print(err)
return
}
_, err = webhook.SendEmbeds(api.NewEmbedBuilder().
SetDescription(msg).
Build(),
)
if err != nil {
log.Print(err)
return
}
if err != nil {
log.Print(err)
}
}