From b17f9299486722ddecabde1c40feee56cfb23947 Mon Sep 17 00:00:00 2001 From: idanoo Date: Sun, 29 Jan 2023 20:26:02 +1300 Subject: [PATCH] Move mastodon URL to a .env var --- .env.example | 13 +++++++------ README.md | 13 ++++++++++++- main.go | 15 ++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.env.example b/.env.example index 93964c1..c8547db 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ -MATRIX_WEBHOOK_URL= -MATRIX_WEBHOOK_API_KEY= -MATRIX_ACCOUNT_CHANNEL= -MATRIX_REPORT_CHANNEL= -PORT= -IP2LOCATION_FILE= +MATRIX_WEBHOOK_URL="http://127.0.0.1:4785" +MATRIX_WEBHOOK_API_KEY=keySetupInMatrixWebhooks +MATRIX_ACCOUNT_CHANNEL="!channelID:matrix.org" +MATRIX_REPORT_CHANNEL="!channelID:matrix.org" +PORT=8081 +IP2LOCATION_FILE="full path to .BIN file" +MASTODON_INSTANCE="mastodon.test" \ No newline at end of file diff --git a/README.md b/README.md index fc565a5..7519527 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,15 @@ Allows you to post signup/report info into a Matrix channel. # Install Install golang. Install [matrix-webhook](https://github.com/nim65s/matrix-webhook). -Copy .env.example to .env and fill in the blanks \ No newline at end of file +Copy .env.example to .env and fill in the blanks + + +``` +MATRIX_WEBHOOK_URL="http://127.0.0.1:4785" +MATRIX_WEBHOOK_API_KEY=keySetupInMatrixWebhooks +MATRIX_ACCOUNT_CHANNEL="!channelID:matrix.org" +MATRIX_REPORT_CHANNEL="!channelID:matrix.org" +PORT=8081 +IP2LOCATION_FILE="full path to .BIN file" +MASTODON_INSTANCE="mastodon.test" +``` \ No newline at end of file diff --git a/main.go b/main.go index 094a64d..b163a0b 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var MATRIX_ACCOUNT_CHANNEL string var MATRIX_REPORT_CHANNEL string var PORT string var IP2LOCATION_FILE string +var MASTODON_INSTANCE string func init() { err := godotenv.Load() @@ -45,6 +46,11 @@ func init() { log.Fatal("MATRIX_REPORT_CHANNEL empty or invalid") } + MASTODON_INSTANCE = os.Getenv("MASTODON_INSTANCE") + if MASTODON_INSTANCE == "" { + log.Fatal("MASTODON_INSTANCE is empty or invalid") + } + PORT = os.Getenv("PORT") if PORT == "" { log.Fatal("PORT empty or invalid") @@ -75,7 +81,8 @@ func handler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf( "[New Report](%s): **%s** has reported **%s**: %s", fmt.Sprintf( - "https://mastodon.nz/admin/reports/%s", + "https://%s/admin/reports/%s", + MASTODON_INSTANCE, i.Object.ID, ), i.Object.Account.Username, @@ -101,7 +108,8 @@ func handler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf( "[New Signup](%s) %s: **%s** (%s). %s", fmt.Sprintf( - "https://mastodon.nz/admin/accounts/%s", + "https://%s/admin/accounts/%s", + MASTODON_INSTANCE, i.Object.ID, ), country, @@ -129,7 +137,8 @@ func handler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf( "[Signup Approved](%s): %s", fmt.Sprintf( - "https://mastodon.nz/admin/accounts/%s", + "https://%s/admin/accounts/%s", + MASTODON_INSTANCE, i.Object.ID, ), i.Object.Username,