-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (32 loc) · 1.08 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
package main
import (
"os"
"github.com/charmbracelet/log"
"github.com/dexslender/orb/commands"
"github.com/dexslender/orb/orb"
"github.com/dexslender/orb/util"
"github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclparse"
)
var version string = "dev"
func main() {
// -----logger
logger := log.NewWithOptions(os.Stderr, log.Options{ReportTimestamp: true})
// -----config
var config orb.Config
parser := hclparse.NewParser()
f, diags := parser.ParseHCLFile("bot.config")
if diags.HasErrors() { log.Fatal("bot.config HCL error: ", diags.Error()) }
mdiags := gohcl.DecodeBody(f.Body, orb.HCLctx, &config)
if mdiags.HasErrors() { log.Fatal("bot.config HCL error: ", mdiags.Error()) }
// -----logger
logger.SetLevel(log.Level(config.Bot.LogLevel))
logger.Debug("config loaded")
// -----bot
bot := orb.New(version, logger, &config)
bot.SetActivityManager(&util.Amanager{Logger: logger, Config: bot.Config})
manager := &util.Imanager{Logger: logger, Config: bot.Config, Orb: bot}
manager.AddCommandsFromPackage(commands.Commands)
bot.SetCommandManager(manager)
bot.Setup()
}