From ff1f9273cb757c70cb96439761458e94de91e3b9 Mon Sep 17 00:00:00 2001 From: Ben Cartwright-Cox Date: Wed, 2 Dec 2020 12:13:13 +0000 Subject: [PATCH] Relax the DISCORD_WEBHOOK requirements, it can be any URL. and if it does not match the discord regex it prints a warning but lets things go ahead, this is handy for debugging and canary subdomains of discord. H/T to Tom Bowditch who discovered the latter part --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index bc60a10..ff83c5d 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "log" "net/http" + "net/url" "os" "regexp" "strings" @@ -86,9 +87,14 @@ func main() { *listenAddress = defaultListenAddress } + _, err := url.Parse(*whURL) + if err != nil { + log.Fatalf("The Discord WebHook URL doesn't seem to be a valid URL.") + } + re := regexp.MustCompile(`https://discord(?:app)?.com/api/webhooks/[0-9]{18}/[a-zA-Z0-9_-]+`) if ok := re.Match([]byte(*whURL)); !ok { - log.Fatalf("The Discord WebHook URL doesn't seem to be valid.") + log.Printf("The Discord WebHook URL doesn't seem to be valid.") } log.Printf("Listening on: %s", *listenAddress)