-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (65 loc) · 1.66 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
73
74
75
76
77
78
79
80
package main
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/juunini/palworld-discord-bot/src/bot"
"github.com/juunini/palworld-discord-bot/src/cli"
"github.com/juunini/palworld-discord-bot/src/config"
"github.com/juunini/palworld-discord-bot/src/console_decoration"
"github.com/juunini/palworld-discord-bot/src/i18n"
"github.com/juunini/palworld-discord-bot/src/palworld/settings"
"github.com/juunini/palworld-discord-bot/src/web"
)
func init() {
if err := config.Load(); err != nil {
config.LANGUAGE = askLanguage()
i18n.SetLanguage(config.LANGUAGE)
if err := config.Save(); err != nil {
panic(err)
}
return
}
i18n.SetLanguage(config.LANGUAGE)
}
func main() {
if config.WEB_SERVER_ENABLED {
go web.Listen(config.WEB_SERVER_PORT)
}
if config.DISCORD_BOT_ENABLED {
session := bot.New(config.DISCORD_BOT_TOKEN)
session.AddHandler(bot.Handler)
bot.Connect(session)
console_decoration.PrintSuccess(i18n.BotRunningStart + "\n")
if config.DISCORD_LOG_CHANNEL_ID != "" || config.DISCORD_DASHBOARD_CHANNEL_ID != "" {
settings.RenewDashboard(session)
go func() {
for {
bot.Watch(session)
time.Sleep(10 * time.Second)
}
}()
}
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
web.Shutdown()
}
func askLanguage() string {
languages := make([]string, len(i18n.Languages))
for i, language := range i18n.Languages {
languages[i] = language["name"]
}
language, err := cli.Choose("Choose your language", languages)
if err != nil {
panic(err)
}
for _, l := range i18n.Languages {
if l["name"] == language {
return l["code"]
}
}
return "en"
}