@@ -16,6 +16,7 @@ import (
16
16
17
17
//Clinet's features
18
18
"github.com/Clinet/clinet_features_dumpctx"
19
+ "github.com/Clinet/clinet_features_essentials"
19
20
"github.com/Clinet/clinet_features_hellodolly"
20
21
"github.com/Clinet/clinet_features_moderation"
21
22
"github.com/Clinet/clinet_features_voice"
@@ -37,58 +38,73 @@ func doBot() {
37
38
//For some reason we don't automatically exit as planned when we return to main()
38
39
defer os .Exit (0 )
39
40
40
- log .Info ("Loading configuration ..." )
41
- cfg , err := config .LoadConfig (configFile , config .ConfigTypeJSON )
41
+ log .Info ("Loading features ..." )
42
+ cfg , err := config .LoadConfig (featuresFile , config .ConfigTypeJSON )
42
43
if err != nil {
43
- log .Error ("Error loading configuration : " , err )
44
+ log .Error ("Error loading features : " , err )
44
45
return
45
46
}
46
47
47
- log .Info ("Syncing configuration..." )
48
- cfg .SaveTo (configFile , config .ConfigTypeJSON )
49
-
50
- if writeConfigTemplate {
51
- log .Info ("Updating configuration template..." )
52
- templateCfg := config .NewConfig ()
53
- templateCfg .Features = append (templateCfg .Features , & features.Feature {Name : "example" , Toggle : true })
54
- templateCfg .SaveTo ("config.template.json" , config .ConfigTypeJSON )
48
+ if cfg .Features == nil || len (cfg .Features ) == 0 {
49
+ log .Error ("No features found in configuration!" )
50
+ return
55
51
}
56
52
53
+ log .Debug ("Syncing format of features file..." )
54
+ cfg .SaveTo (featuresFile , config .ConfigTypeJSON )
55
+
56
+ //Initialize Clinet using the configuration provided
57
+ log .Info ("Initializing instance of Clinet..." )
57
58
clinet = bot .NewBot (cfg )
59
+
60
+ //Clinet is effectively online at this stage, so defer shutdown in case of errors below
58
61
defer clinet .Shutdown ()
59
62
60
- log .Debug ("Registering features..." )
61
- if err := clinet .RegisterFeature (dumpctx .Feature ); err != nil {
62
- log .Fatal (err )
63
- }
64
- if err := clinet .RegisterFeature (hellodolly .Feature ); err != nil {
65
- log .Fatal (err )
66
- }
67
- if err := clinet .RegisterFeature (moderation .Feature ); err != nil {
68
- log .Fatal (err )
69
- }
70
- if err := clinet .RegisterFeature (voice .Feature ); err != nil {
71
- log .Fatal (err )
72
- }
63
+ //Register the conversation services to handle queries
64
+ log .Debug ("Registering conversation services..." )
65
+ log .Trace ("- duckduckgo" )
66
+ logFatalError (clinet .RegisterFeature (duckduckgo .Feature ))
67
+ log .Trace ("- wolframalpha" )
68
+ logFatalError (clinet .RegisterFeature (wolframalpha .Feature ))
73
69
74
- if err := clinet .RegisterConvoService ("duckduckgo" , duckduckgo .DuckDuckGo ); err != nil {
75
- log .Fatal (err )
76
- }
77
- if err := clinet .RegisterConvoService ("wolframalpha" , wolframalpha .WolframAlpha ); err != nil {
78
- log .Fatal (err )
70
+ //Register the features to handle commands
71
+ log .Debug ("Registering features..." )
72
+ log .Trace ("- dumpctx" )
73
+ logFatalError (clinet .RegisterFeature (dumpctx .Feature ))
74
+ log .Trace ("- hellodolly" )
75
+ logFatalError (clinet .RegisterFeature (hellodolly .Feature ))
76
+ log .Trace ("- moderation" )
77
+ logFatalError (clinet .RegisterFeature (moderation .Feature ))
78
+ log .Trace ("- voice" )
79
+ logFatalError (clinet .RegisterFeature (voice .Feature ))
80
+ log .Trace ("- essentials" )
81
+ logFatalError (clinet .RegisterFeature (essentials .Feature )) //ALWAYS REGISTER ESSENTIALS LAST BEFORE CHAT SERVICES!
82
+
83
+ log .Debug ("Registering chat services..." )
84
+ log .Trace ("- discord" )
85
+ logFatalError (clinet .RegisterFeature (discord .Feature ))
86
+ log .Trace ("- guilded" )
87
+ logFatalError (clinet .RegisterFeature (guilded .Feature ))
88
+
89
+ if writeFeaturesTemplate {
90
+ log .Debug ("Updating features template..." )
91
+ templateCfg := config .NewConfig ()
92
+ templateCfg .Features = features .FM .Features
93
+ templateCfg .SaveTo ("features.template.json" , config .ConfigTypeJSON )
79
94
}
80
95
81
- if err := clinet .RegisterService ("discord" , discord .Discord ); err != nil {
82
- log .Fatal (err )
83
- }
84
- if err := clinet .RegisterService ("guilded" , guilded .Guilded ); err != nil {
85
- log .Fatal (err )
86
- }
96
+ log .Info ("Clinet is now online!" )
87
97
88
98
log .Debug ("Waiting for SIGINT syscall signal..." )
89
99
sc := make (chan os.Signal , 1 )
90
100
signal .Notify (sc , syscall .SIGINT )
91
101
<- sc
92
102
93
103
log .Info ("Good-bye!" )
104
+ }
105
+
106
+ func logFatalError (err error ) {
107
+ if err != nil {
108
+ log .Fatal (err )
109
+ }
94
110
}
0 commit comments