forked from automuteus/automuteus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (53 loc) · 1.61 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
package main
import (
"errors"
"log"
"os"
"strconv"
"time"
"github.com/denverquane/amongusdiscord/discord"
"github.com/joho/godotenv"
)
const DefaultPort = "8123"
func main() {
err := discordMainWrapper()
if err != nil {
log.Println("Program exited with the following error:")
log.Println(err)
log.Println("This window will automatically terminate in 10 seconds")
time.Sleep(10 * time.Second)
return
}
}
func discordMainWrapper() error {
err := godotenv.Load("final.env")
if err != nil {
err = godotenv.Load("final.txt")
if err != nil {
log.Println("Can't open env file, hopefully you're running in docker and have provided the DISCORD_BOT_TOKEN...")
}
}
discordToken := os.Getenv("DISCORD_BOT_TOKEN")
if discordToken == "" {
return errors.New("no DISCORD_BOT_TOKEN provided")
}
//TODO disabled move dead players for pre-release for a solid baseline of features
//discordMoveDeadPlayersStr := os.Getenv("DISCORD_MOVE_DEAD_PLAYERS")
discordMoveDeadPlayers := false
//ret, err := strconv.ParseBool(discordMoveDeadPlayersStr)
//if err == nil {
// log.Printf("Using DISCORD_MOVE_DEAD_PLAYERS %t\n", ret)
// discordMoveDeadPlayers = ret
//} else {
// log.Printf("Problem parsing DISCORD_MOVE_DEAD_PLAYERS; using %t as default\n", discordMoveDeadPlayers)
//}
port := os.Getenv("SERVER_PORT")
num, err := strconv.Atoi(port)
if err != nil || num < 1000 || num > 9999 {
log.Printf("Invalid or no particular SERVER_PORT provided. Defaulting to %s\n", DefaultPort)
port = DefaultPort
}
//start the discord bot
discord.MakeAndStartBot(discordToken, discordMoveDeadPlayers, port)
return nil
}