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
/
main.go
61 lines (50 loc) · 1.92 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
package main
import (
"os"
"github.com/Clinet/clinet/config"
"github.com/Clinet/clinet/discord"
"github.com/JoshuaDoes/logger"
flag "github.com/spf13/pflag"
)
var (
//Various command-line flags
configFile string //path to bot configuration
writeConfigTemplate bool //if true, write the current configuration template to config.template.json
verbosity int //0 = default (info, warning, error), 1 = 0 + debug, 2 = 1 + trace
isBot bool //if true, act as the bot process instead of the watchdog process
killOldBot bool //if true, search for dangling bot processes and kill them
watchdogPID int //stores the watchdog PID if acting as a bot process, used as the exception when killing old bot processes
//Logging
log *logger.Logger
logPrefix string = "WATCHDOG"
)
func init() {
//Apply all command-line flags
flag.StringVar(&configFile, "config", "config.json", "path to bot configuration")
flag.BoolVar(&writeConfigTemplate, "writeConfigTemplate", true, "write the current configuration template to config.template.json")
flag.IntVar(&verbosity, "verbosity", 0, "sets the verbosity level; 0 = default, 1 = debug, 2 = trace")
flag.BoolVar(&isBot, "isBot", false, "act as the bot process instead of the watchdog process")
flag.BoolVar(&killOldBot, "killOldBot", false, "search for dangling bot processes and kill them")
flag.IntVar(&watchdogPID, "watchdogPID", -1, "used as the exception when killing old bot processes, requires --killOldBot")
flag.Parse()
//Create the logger
if isBot {
logPrefix = "BOT" //We're the bot process, report as such
}
log = logger.NewLogger(logPrefix, verbosity)
//Assign the logger to each package
config.Log = log
discord.Log = log
}
func main() {
log.Trace("--- main() ---")
if watchdogPID == -1 {
log.Info("Clinet © JoshuaDoes: 2017-2021.")
}
if isBot {
doBot()
os.Exit(0)
}
doWatchdog()
log.Info("Good-bye!")
}