I think things are pretty good
This commit is contained in:
13
app/app.go
13
app/app.go
@@ -9,8 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type App struct {
|
||||
debug bool
|
||||
Running bool
|
||||
debug bool
|
||||
|
||||
m *models.BotModel
|
||||
|
||||
@@ -28,7 +27,6 @@ func NewApp(debugMode bool) (*App, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.Running = true
|
||||
go a.watchMessageChannel()
|
||||
return a, err
|
||||
}
|
||||
@@ -54,6 +52,7 @@ func (a *App) initialize() error {
|
||||
if a.m, err = models.NewBotModel(a.debug); err != nil {
|
||||
return err
|
||||
}
|
||||
a.m.Running = true
|
||||
|
||||
// Load up the plugins
|
||||
a.plugins = append(a.plugins, &plugins.StatsState{}, &plugins.AoCState{})
|
||||
@@ -69,6 +68,9 @@ func (a *App) initialize() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *App) Stop() { a.m.Running = false }
|
||||
func (a *App) IsRunning() bool { return a.m.Running }
|
||||
|
||||
func (a *App) SendQuitMessage() { a.m.SendMessage(models.QuitMessage) }
|
||||
|
||||
func (a *App) setupMessageWatchers() {
|
||||
@@ -76,7 +78,7 @@ func (a *App) setupMessageWatchers() {
|
||||
if msg.Is(models.QuitMessage) {
|
||||
// App is shutting down
|
||||
fmt.Println("Received QuitMessage")
|
||||
a.Running = false
|
||||
a.m.Running = false
|
||||
} else if msg.IsError() {
|
||||
// Received an Error Message
|
||||
fmt.Printf("ERROR: %s\n", msg)
|
||||
@@ -89,14 +91,13 @@ func (a *App) setupMessageWatchers() {
|
||||
})
|
||||
|
||||
for _, v := range a.plugins {
|
||||
fmt.Println("Setting up watchers for", v.Name())
|
||||
a.m.AddMessageWatcher(fmt.Sprintf("plugin-%s", v.Name()), v.ProcessMessage)
|
||||
a.m.AddRTMWatcher(fmt.Sprintf("plugin-%s", v.Name()), v.ProcessRTMEvent)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) watchMessageChannel() {
|
||||
for a.Running {
|
||||
for a.m.Running {
|
||||
a.m.ProcessMessageChannel()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user