post to irc

This commit is contained in:
an 2018-04-22 11:39:52 +02:00
parent 80f2f13aee
commit 41be481497
1 changed files with 10 additions and 2 deletions

View File

@ -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
}
}
}