From 41be48149752a47fb8c999818ccd5ce59207df76 Mon Sep 17 00:00:00 2001 From: an Date: Sun, 22 Apr 2018 11:39:52 +0200 Subject: [PATCH] post to irc --- modules/webhook.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/webhook.go b/modules/webhook.go index bc7451b..45911c1 100644 --- a/modules/webhook.go +++ b/modules/webhook.go @@ -4,13 +4,18 @@ package modules import ( "encoding/json" + "flag" "fmt" - "log" "net/http" "git.dnix.de/an/xlog" ) +var ( + webhookPort = flag.String("webhook_port", "8080", "Webhook listener port") + webhookChan = flag.String("webhook_chan", "", "Channel to post into") +) + func init() { MsgFuncs["webhook"] = webhookHandleMessage RunFuncs["webhook"] = webhookRun @@ -19,7 +24,7 @@ func init() { func webhookRun() { xlog.Info("webhook listener started") http.HandleFunc("/webhook", webhookHandleHTTP) - log.Fatal(http.ListenAndServe(":8080", nil)) + xlog.Fatal(http.ListenAndServe(":"+*webhookPort, nil)) } func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) { @@ -32,6 +37,9 @@ func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) { fmt.Println("got webhook payload: ") for k, v := range data { fmt.Printf("%s : %v\n", k, v) + if k == "text" { + sayCh <- *webhookChan + "\n" + v + } } }