Working on things... Considering a slack library change

This commit is contained in:
Brian Buller 2019-11-21 11:09:06 -06:00
parent 8f70393598
commit 8909975cce
5 changed files with 13 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
cmd/plugins/*
cmd/helperbot
cmd/*.db
cmd/cmd
helperbot.tgz

View File

@ -23,11 +23,12 @@ func NewApp() (*App, error) {
}
a.DebugMode = DebugMode
a.running = true
err := a.initialize()
if err != nil {
a.running = false
return nil, err
}
a.running = true
go a.MonitorSlackMessages()
return a, nil
@ -64,10 +65,12 @@ func (a *App) initialize() error {
a.m.setSlackAdminDMId(strings.TrimSpace(slackDMid))
}
fmt.Println("Creating Slack Model")
if err = a.m.NewSlack(); err != nil {
return err
}
fmt.Println("Starting gofunc watchMessageChannel")
go a.watchMessageChannel()
return nil
}
@ -76,6 +79,9 @@ func (a *App) watchMessageChannel() {
for a.running {
msg := <-a.m.messages
slackMsg := msg.GetMessage()
if slackMsg.Type != "user_typing" {
fmt.Println(slackMsg)
}
if slackMsg.Type == "control" && slackMsg.Name == "quit" {
a.running = false
break
@ -89,5 +95,4 @@ func (a *App) watchMessageChannel() {
v.State.ProcessMessage(msg)
}
}
close(a.m.messages)
}

View File

@ -26,19 +26,20 @@ func (a *App) LoadPluginsFromDirectory(dir string) error {
for _, f := range files {
p, err := plugin.Open(dir + f.Name())
if err != nil {
fmt.Println(fmt.Sprintf("Error loading plugin (%s)\n", f.Name()))
fmt.Printf("Error loading plugin (%s)\n", f.Name())
fmt.Println(err.Error())
os.Exit(1)
}
hp, err := NewHelperPlugin(p)
if err != nil {
fmt.Println(fmt.Sprintf("Error loading plugin (%s)\n", f.Name()))
fmt.Printf("Error loading plugin (%s)\n", f.Name())
fmt.Println(err.Error())
os.Exit(1)
}
hp.State.Initialize(a.m)
hp.State.Run()
a.plugins = append(a.plugins, *hp)
fmt.Printf("Plugin loaded: %s\n", f.Name())
}
return nil
}

View File

@ -26,11 +26,6 @@ func main() {
os.Exit(1)
}
// Monitor the Advent of Code Boards
//go m.MonitorAoCBoards()
// Monitor incoming Slack messages
//go m.MonitorSlackMessages()
// Set up a channel to intercept Ctrl+C for graceful shutdowns
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
@ -43,7 +38,6 @@ func main() {
for a.running {
time.Sleep(time.Second * 2)
}
fmt.Println("Model has stopped running")
fmt.Println("Done")
os.Exit(0)
}

View File

@ -4,6 +4,8 @@ import (
slack "git.bullercodeworks.com/brian/go-slack"
)
// TODO: Look into switching to: https://github.com/nlopes/slack
/* DB Functions */
func (m *BotModel) setSlackToken(token string) error {
return m.SetBytes([]string{"slack", "config", "token"}, []byte(token))