-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (43 loc) · 1.33 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
package main
import (
"context"
"fmt"
"os"
"syscall"
"github.com/Libera-Chat/murdochite/bot"
"github.com/op/go-logging"
"github.com/pelletier/go-toml/v2"
)
// Version of the bot
var Version = "Unknown" // nolint:gochecknoglobals // set by the linker
func main() {
//nolint:lll,misspell // cannot be shortened, and I'd love to spell correctly but the dev was apparently american.
const format = "%{color}[%{time:15:04:05.0000}] [%{level: -8s}]%{color:reset} [%{module: -15s}] [%{shortfile: -20s}] %{message}"
logging.SetFormatter(logging.MustStringFormatter(format))
logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0))
var config bot.Config
data, err := os.ReadFile("./config.toml")
if err != nil {
fmt.Printf("Could not read config file: %s\n", err)
os.Exit(1)
}
if err := toml.Unmarshal(data, &config); err != nil {
fmt.Printf("Could not parse config file: %s\n", err)
os.Exit(1)
}
config.Version = Version
mainLogger := logging.MustGetLogger("main")
mainLogger.Infof("Starting version %s...", Version)
b, err := bot.New(&config, logging.MustGetLogger("bot"))
if err != nil {
mainLogger.Fatalf("Could not instantiate bot: %s", err)
}
b.Run(context.Background())
if b.ShouldRestart {
exe, err := os.Executable()
if err != nil {
panic(err)
}
panic(syscall.Exec(exe, os.Args, os.Environ()))
}
}