post to irc
This commit is contained in:
parent
80f2f13aee
commit
41be481497
|
@ -4,13 +4,18 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.dnix.de/an/xlog"
|
"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() {
|
func init() {
|
||||||
MsgFuncs["webhook"] = webhookHandleMessage
|
MsgFuncs["webhook"] = webhookHandleMessage
|
||||||
RunFuncs["webhook"] = webhookRun
|
RunFuncs["webhook"] = webhookRun
|
||||||
|
@ -19,7 +24,7 @@ func init() {
|
||||||
func webhookRun() {
|
func webhookRun() {
|
||||||
xlog.Info("webhook listener started")
|
xlog.Info("webhook listener started")
|
||||||
http.HandleFunc("/webhook", webhookHandleHTTP)
|
http.HandleFunc("/webhook", webhookHandleHTTP)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
xlog.Fatal(http.ListenAndServe(":"+*webhookPort, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func webhookHandleHTTP(w http.ResponseWriter, r *http.Request) {
|
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: ")
|
fmt.Println("got webhook payload: ")
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
fmt.Printf("%s : %v\n", k, v)
|
fmt.Printf("%s : %v\n", k, v)
|
||||||
|
if k == "text" {
|
||||||
|
sayCh <- *webhookChan + "\n" + v
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue