This commit is contained in:
mimu
2022-10-09 09:03:48 +02:00
parent e66eeaf9ba
commit f544f18047
2 changed files with 32 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
.env env.go
+31 -6
View File
@@ -11,10 +11,12 @@ import (
) )
func main() { func main() {
env := getEnvVariables()
client := tempest.CreateClient(tempest.ClientOptions{ client := tempest.CreateClient(tempest.ClientOptions{
ApplicationId: tempest.StringToSnowflake(os.Getenv("APP_ID")), ApplicationId: env.AppID,
PublicKey: os.Getenv("PUBLIC_KEY"), PublicKey: env.PublicKey,
Token: os.Getenv("TOKEN"), Token: env.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
@@ -39,10 +41,33 @@ func main() {
}, nil, false) }, nil, false)
addr := os.Getenv("RAILWAY_STATIC_URL") addr := fmt.Sprintf("%s:%s", env.Addr, env.Port)
if err := client.ListenAndServe(fmt.Sprintf("%s:80", addr)); err != nil { fmt.Println("starting server at", addr)
if err := client.ListenAndServe(addr); err != nil {
panic(err) panic(err)
} }
fmt.Println("starting server at", addr) }
func getEnvVariables() Env {
if os.Getenv("RAILWAY_ENVIRONMENT") == "production" {
return Env{
AppID: tempest.StringToSnowflake(os.Getenv("APP_ID")),
PublicKey: os.Getenv("PUBLIC_KEY"),
Token: os.Getenv("TOKEN"),
Port: "8080",
}
}
return LocalEnv
}
type Env struct {
AppID tempest.Snowflake
PublicKey string
Token string
Port string
Addr string
} }