forked from divideprojects/RestrictChannelRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (45 loc) · 1.15 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"flag"
"log"
"os"
"strconv"
)
// Environmental variables.
var (
enableWebhook bool
webhookPort int
botToken string
webhookDomain string
databaseUrl string
databaseName string
webhookSecret string
)
func init() {
flag.StringVar(&botToken, "BOT_TOKEN", os.Getenv("BOT_TOKEN"), "Bot token for running the bot")
flag.BoolVar(&enableWebhook, "USE_WEBHOOKS", func() bool {
return os.Getenv("USE_WEBHOOKS") == "yes" || os.Getenv("USE_WEBHOOKS") == "true"
}(),
"Enable webhooks",
)
flag.StringVar(&webhookSecret, "WEBHOOK_SECRET", os.Getenv("WEBHOOK_SECRET"), "Secret for webhook")
flag.StringVar(&webhookDomain, "WEBHOOK_DOMAIN", os.Getenv("WEBHOOK_DOMAIN"), "URL for the Webhook")
flag.IntVar(
&webhookPort,
"PORT",
func(value string) int {
if value == "" {
return 0
}
val, err := strconv.Atoi(value)
if err != nil {
log.Fatal(err)
return 0
}
return val
}(os.Getenv("PORT")),
"Port for the webhook",
)
flag.StringVar(&databaseUrl, "DB_URI", os.Getenv("DB_URI"), "Database URI for MongoDB")
flag.StringVar(&databaseName, "DB_NAME", os.Getenv("DB_NAME"), "Bot database name in MongoDB")
}