use env variables

This commit is contained in:
mimu
2022-10-09 08:20:26 +02:00
parent 7061028af3
commit 6dd9cc219a
2 changed files with 12 additions and 10 deletions
+1
View File
@@ -0,0 +1 @@
.env
+11 -10
View File
@@ -4,21 +4,19 @@ import (
"fmt" "fmt"
"hal/commands" "hal/commands"
"log" "log"
"os"
"time" "time"
tempest "github.com/Amatsagu/Tempest" 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() { func main() {
fmt.Println("### ENV ###", os.Getenv("TOKEN"))
client := tempest.CreateClient(tempest.ClientOptions{ client := tempest.CreateClient(tempest.ClientOptions{
ApplicationId: AppID, ApplicationId: tempest.StringToSnowflake(os.Getenv("APP_ID")),
PublicKey: PublicKey, PublicKey: os.Getenv("PUBLIC_KEY"),
Token: Token, Token: os.Getenv("TOKEN"),
PreCommandExecutionHandler: func(itx tempest.CommandInteraction) *tempest.ResponseData { PreCommandExecutionHandler: func(itx tempest.CommandInteraction) *tempest.ResponseData {
log.Printf("running [%s] slash command", itx.Data.Name) log.Printf("running [%s] slash command", itx.Data.Name)
return nil return nil
@@ -34,7 +32,6 @@ func main() {
}, },
}) })
log.Printf("starting server at %s", Addr)
client.RegisterCommand(commands.Hello) client.RegisterCommand(commands.Hello)
client.RegisterCommand(commands.Pinned) client.RegisterCommand(commands.Pinned)
@@ -43,7 +40,11 @@ func main() {
992760761812258868, // test server 992760761812258868, // test server
}, nil, false) }, nil, false)
if err := client.ListenAndServe(Addr); err != nil {
addr := os.Getenv("RAILWAY_STATIC_URL")
if err := client.ListenAndServe(addr); err != nil {
panic(err) panic(err)
} }
log.Printf("starting server at %s", addr)
} }