This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
80 lines (65 loc) · 1.94 KB
/
bot.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 (
//std necessities
"os"
"os/signal"
"syscall"
"github.com/Clinet/clinet/cmds"
"github.com/Clinet/clinet/config"
"github.com/Clinet/clinet/convos"
"github.com/Clinet/clinet/discord"
"github.com/Clinet/clinet/features"
"github.com/Clinet/clinet/features/dumpctx"
"github.com/Clinet/clinet/features/hellodolly"
"github.com/JoshuaDoes/go-wolfram"
)
//Global error value because functions are mean
var err error
var (
cfg *config.Config
)
func doBot() {
//For some reason we don't automatically exit as planned when we return to main()
defer os.Exit(0)
log.Trace("--- doBot() ---")
log.Info("Loading configuration...")
cfg, err = config.LoadConfig(configFile, config.ConfigTypeJSON)
if err != nil {
log.Error("Error loading configuration: ", err)
}
log.Info("Syncing configuration...")
cfg.SaveTo(configFile, config.ConfigTypeJSON)
if writeConfigTemplate {
log.Info("Updating configuration template...")
var templateCfg *config.Config = &config.Config{
Features: []*features.Feature{&features.Feature{Name: "example", Toggle: true}},
Discord: &discord.CfgDiscord{},
WolframAlpha: &wolfram.Client{},
}
templateCfg.SaveTo("config.template.json", config.ConfigTypeJSON)
}
log.Debug("Setting feature toggles...")
features.SetFeatures(cfg.Features)
log.Debug("Registering features...")
if features.IsEnabled("dumpctx") {
cmds.Commands = append(cmds.Commands, dumpctx.CmdRoot)
}
if features.IsEnabled("hellodolly") {
cmds.Commands = append(cmds.Commands, hellodolly.CmdRoot)
}
log.Debug("Enabling services...")
convos.AuthWolframAlpha(cfg.WolframAlpha)
log.Trace("- Wolfram|Alpha")
//Load modules
log.Info("Loading modules...")
loadModules()
//Start Discord
log.Info("Starting Discord...")
discord.StartDiscord(cfg.Discord)
defer discord.Discord.Close()
log.Debug("Waiting for SIGINT syscall signal...")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT)
<-sc
log.Info("Good-bye!")
}