This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (61 loc) · 1.71 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"log"
"os"
"github.com/devit-tel/discord-bot-go/pkg/discord"
"github.com/devit-tel/discord-bot-go/pkg/server"
"github.com/joho/godotenv"
)
var (
verifyServiceBaseURL string
emailServiceURL string
discordToken string
discordChannelID string
discordServerID string
key []byte
serverAddress string
emailRegexp string
)
func main() {
setupEnv()
session, err := discord.SetupDiscord(discord.Config{
Key: key,
DiscordServerID: discordServerID,
DiscordChannelID: discordChannelID,
AllowedEmailRegexp: emailRegexp,
EmailServiceURL: emailServiceURL,
VerifyServiceBaseURL: verifyServiceBaseURL,
}, discordToken)
if err != nil {
log.Panicln(err)
}
r := server.SetupServer(key, server.DiscordConfig{
Session: session,
DiscordChannelID: discordChannelID,
DiscordServerID: discordServerID,
})
err = r.Run(serverAddress)
if err != nil {
log.Panicln(err)
}
}
func setupEnv() {
if err := godotenv.Load(); err != nil {
log.Println("Error loading .env file")
}
verifyServiceBaseURL = getEnv("VERIFY_SERVICE_BASE_URL", "")
emailServiceURL = getEnv("EMAIL_SERVICE_URL", "")
discordToken = getEnv("DISCORD_TOKEN", "")
discordChannelID = getEnv("DISCORD_CHANNEL_ID", "")
discordServerID = getEnv("DISCORD_SERVER_ID", "")
key = []byte(getEnv("PASSPHRASE", "P4S$W0Rd_Th41_5i2e_32_by7E_long!"))[:32]
serverAddress = getEnv("SERVER_ADDRESS", ":8080")
emailRegexp = getEnv("EMAIL_REGEXP", "(?i)^[0-9a-z_\\-]{1,64}@[a-z]{1,64}.[0-9a-z]{1.3}")
}
func getEnv(key string, defaultValue string) string {
value := os.Getenv(key)
if len(value) == 0 {
return defaultValue
}
return value
}