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() {
env := getEnvVariables()
client := tempest.CreateClient(tempest.ClientOptions{
ApplicationId: tempest.StringToSnowflake(os.Getenv("APP_ID")),
PublicKey: os.Getenv("PUBLIC_KEY"),
Token: os.Getenv("TOKEN"),
ApplicationId: env.AppID,
PublicKey: env.PublicKey,
Token: env.Token,
PreCommandExecutionHandler: func(itx tempest.CommandInteraction) *tempest.ResponseData {
log.Printf("running [%s] slash command", itx.Data.Name)
return nil
@@ -39,10 +41,33 @@ func main() {
}, nil, false)
addr := os.Getenv("RAILWAY_STATIC_URL")
if err := client.ListenAndServe(fmt.Sprintf("%s:80", addr)); err != nil {
addr := fmt.Sprintf("%s:%s", env.Addr, env.Port)
fmt.Println("starting server at", addr)
if err := client.ListenAndServe(addr); err != nil {
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
}