-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
145 lines (116 loc) · 3.09 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"flag"
"fmt"
"github.com/dmportella/qilbot/bot"
"github.com/dmportella/qilbot/logging"
//"github.com/dmportella/qilbot/plugins/eddb"
"github.com/dmportella/qilbot/plugins/edsm"
//"github.com/dmportella/qilbot/plugins/wow"
"io/ioutil"
"os"
"os/signal"
)
// Set on build
var (
Build string
Branch string
Revision string
OSArch string
)
// Variables used for command line parameters
var (
Email string
Password string
Token string
BotID string
Version bool
Verbose bool
)
var (
botInstance bot.Qilbot
)
func init() {
const (
defaultEmail = ""
emailUsage = "The email of te discord user. Not required if -bot-token is provided."
defaultPassword = ""
passwordUsage = "The password of te discord user. Not required if -bot-token is provided."
defaultToken = ""
tokenUsage = "The token for the dicord bot. For more information please visit: https://discordapp.com/developers"
)
flag.StringVar(&Email, "user-email", defaultEmail, emailUsage)
flag.StringVar(&Password, "user-password", defaultPassword, passwordUsage)
flag.StringVar(&Token, "bot-token", defaultToken, tokenUsage)
flag.StringVar(&Email, "e", defaultEmail, emailUsage)
flag.StringVar(&Password, "p", defaultPassword, passwordUsage)
flag.StringVar(&Token, "t", defaultToken, tokenUsage)
const (
defaultVerbose = false
verboseUsage = "Redirect trace information to the standard out."
)
flag.BoolVar(&Verbose, "verbose", defaultVerbose, verboseUsage)
flag.Parse()
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
}
func main() {
fmt.Printf("Qilbot - Version: %s Branch: %s Revision: %s. OSArch: %s.\n\rDaniel Portella (c) 2016\n\r", Build, Branch, Revision, OSArch)
if Verbose {
logging.Init(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
} else {
logging.Init(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
}
if len(os.Args) == 1 {
flag.Usage()
os.Exit(1)
}
if Password == "" && Email == "" && Token == "" {
logging.Error.Println("Please provide credentials.")
os.Exit(1)
}
botConfig := bot.QilbotConfig{
Email: Email,
Password: Password,
Token: Token,
Debug: Verbose,
}
bot, ok := bot.New(&botConfig)
if ok != nil {
os.Exit(2)
} else {
botInstance = *bot
}
loadPlugins()
go startbot()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
if sig.String() == "interrupt" {
logging.Info.Printf("Application ended on %s\n\r", sig)
bot.Stop()
os.Exit(0)
}
}
}()
// Simple way to keep program running until CTRL-C is pressed.
<-make(chan struct{})
}
func loadPlugins() {
//eddbPlugin := eddb.NewPlugin(&botInstance)
//logging.Info.Println(eddbPlugin.Name(), "loaded")
edsmPlugin := edsm.NewPlugin(&botInstance)
logging.Info.Println(edsmPlugin.Name(), "loaded")
//wowPlugin := wow.NewPlugin(&botInstance)
//logging.Info.Println(wowPlugin.Name(), "loaded")
}
func startbot() {
if ok := botInstance.Start(); ok == nil {
logging.Info.Println("Bot is now running. Press CTRL-C to exit.")
} else {
panic(ok)
}
}