From 6dd9cc219ac4bff3cf24b3264a13ae939dcb022b Mon Sep 17 00:00:00 2001 From: mimu Date: Sun, 9 Oct 2022 08:20:26 +0200 Subject: [PATCH] use env variables --- .gitignore | 1 + main.go | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/main.go b/main.go index edd4329..d9ce337 100644 --- a/main.go +++ b/main.go @@ -4,21 +4,19 @@ import ( "fmt" "hal/commands" "log" + "os" "time" tempest "github.com/Amatsagu/Tempest" ) -const AppID tempest.Snowflake = 123 -const PublicKey string = "public_key" -const Token string = "token" -const Addr string = "0.0.0.0:8080" - func main() { + fmt.Println("### ENV ###", os.Getenv("TOKEN")) + client := tempest.CreateClient(tempest.ClientOptions{ - ApplicationId: AppID, - PublicKey: PublicKey, - Token: Token, + ApplicationId: tempest.StringToSnowflake(os.Getenv("APP_ID")), + PublicKey: os.Getenv("PUBLIC_KEY"), + Token: os.Getenv("TOKEN"), PreCommandExecutionHandler: func(itx tempest.CommandInteraction) *tempest.ResponseData { log.Printf("running [%s] slash command", itx.Data.Name) return nil @@ -34,7 +32,6 @@ func main() { }, }) - log.Printf("starting server at %s", Addr) client.RegisterCommand(commands.Hello) client.RegisterCommand(commands.Pinned) @@ -43,7 +40,11 @@ func main() { 992760761812258868, // test server }, nil, false) - if err := client.ListenAndServe(Addr); err != nil { + + addr := os.Getenv("RAILWAY_STATIC_URL") + if err := client.ListenAndServe(addr); err != nil { panic(err) } + + log.Printf("starting server at %s", addr) }