mirror of
https://github.com/idanoo/go-mastodon-matrix-webhooks.git
synced 2024-11-22 08:25:17 +00:00
Reports to different channel
This commit is contained in:
parent
d703c674b7
commit
de0cd3496a
@ -1,5 +1,6 @@
|
||||
MATRIX_WEBHOOK_URL=
|
||||
MATRIX_WEBHOOK_API_KEY=
|
||||
MATRIX_CHANNEL=
|
||||
MATRIX_ACCOUNT_CHANNEL=
|
||||
MATRIX_REPORT_CHANNEL=
|
||||
PORT=
|
||||
IP2LOCATION_FILE=
|
22
main.go
22
main.go
@ -14,7 +14,8 @@ import (
|
||||
|
||||
var MATRIX_WEBHOOK_URL string
|
||||
var MATRIX_WEBHOOK_API_KEY string
|
||||
var MATRIX_CHANNEL string
|
||||
var MATRIX_ACCOUNT_CHANNEL string
|
||||
var MATRIX_REPORT_CHANNEL string
|
||||
var PORT string
|
||||
var IP2LOCATION_FILE string
|
||||
|
||||
@ -34,9 +35,14 @@ func init() {
|
||||
log.Fatal("MATRIX_WEBHOOK_API_KEY empty or invalid")
|
||||
}
|
||||
|
||||
MATRIX_CHANNEL = os.Getenv("MATRIX_CHANNEL")
|
||||
if MATRIX_CHANNEL == "" {
|
||||
log.Fatal("MATRIX_CHANNEL empty or invalid")
|
||||
MATRIX_ACCOUNT_CHANNEL = os.Getenv("MATRIX_ACCOUNT_CHANNEL")
|
||||
if MATRIX_ACCOUNT_CHANNEL == "" {
|
||||
log.Fatal("MATRIX_ACCOUNT_CHANNEL empty or invalid")
|
||||
}
|
||||
|
||||
MATRIX_REPORT_CHANNEL = os.Getenv("MATRIX_REPORT_CHANNEL")
|
||||
if MATRIX_REPORT_CHANNEL == "" {
|
||||
log.Fatal("MATRIX_REPORT_CHANNEL empty or invalid")
|
||||
}
|
||||
|
||||
PORT = os.Getenv("PORT")
|
||||
@ -76,6 +82,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
i.Object.TargetAccount.Username,
|
||||
i.Object.Comment,
|
||||
),
|
||||
MATRIX_REPORT_CHANNEL,
|
||||
)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
@ -98,6 +105,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
i.Object.Notes,
|
||||
),
|
||||
),
|
||||
MATRIX_ACCOUNT_CHANNEL,
|
||||
)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
@ -108,7 +116,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// sendWebhook - takes msg, sends to matrix
|
||||
func sendWebhook(msgText string) error {
|
||||
func sendWebhook(msgText string, channel string) error {
|
||||
// log.Println(msgText)
|
||||
data := MatrixWebhook{
|
||||
Key: MATRIX_WEBHOOK_API_KEY,
|
||||
@ -119,8 +127,8 @@ func sendWebhook(msgText string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// log.Printf("Sending %s to %s", b, MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL)
|
||||
req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+MATRIX_CHANNEL, bytes.NewBuffer(b))
|
||||
// log.Printf("Sending %s to %s", b, MATRIX_WEBHOOK_URL+"/"+channel)
|
||||
req, err := http.NewRequest("POST", MATRIX_WEBHOOK_URL+"/"+channel, bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user