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/plugins/*
cmd/helperbot cmd/helperbot
cmd/*.db cmd/*.db
cmd/cmd
helperbot.tgz helperbot.tgz

View File

@ -23,11 +23,12 @@ func NewApp() (*App, error) {
} }
a.DebugMode = DebugMode a.DebugMode = DebugMode
a.running = true
err := a.initialize() err := a.initialize()
if err != nil { if err != nil {
a.running = false
return nil, err return nil, err
} }
a.running = true
go a.MonitorSlackMessages() go a.MonitorSlackMessages()
return a, nil return a, nil
@ -64,10 +65,12 @@ func (a *App) initialize() error {
a.m.setSlackAdminDMId(strings.TrimSpace(slackDMid)) a.m.setSlackAdminDMId(strings.TrimSpace(slackDMid))
} }
fmt.Println("Creating Slack Model")
if err = a.m.NewSlack(); err != nil { if err = a.m.NewSlack(); err != nil {
return err return err
} }
fmt.Println("Starting gofunc watchMessageChannel")
go a.watchMessageChannel() go a.watchMessageChannel()
return nil return nil
} }
@ -76,6 +79,9 @@ func (a *App) watchMessageChannel() {
for a.running { for a.running {
msg := <-a.m.messages msg := <-a.m.messages
slackMsg := msg.GetMessage() slackMsg := msg.GetMessage()
if slackMsg.Type != "user_typing" {
fmt.Println(slackMsg)
}
if slackMsg.Type == "control" && slackMsg.Name == "quit" { if slackMsg.Type == "control" && slackMsg.Name == "quit" {
a.running = false a.running = false
break break
@ -89,5 +95,4 @@ func (a *App) watchMessageChannel() {
v.State.ProcessMessage(msg) 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 { for _, f := range files {
p, err := plugin.Open(dir + f.Name()) p, err := plugin.Open(dir + f.Name())
if err != nil { 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()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
} }
hp, err := NewHelperPlugin(p) hp, err := NewHelperPlugin(p)
if err != nil { 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()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
} }
hp.State.Initialize(a.m) hp.State.Initialize(a.m)
hp.State.Run() hp.State.Run()
a.plugins = append(a.plugins, *hp) a.plugins = append(a.plugins, *hp)
fmt.Printf("Plugin loaded: %s\n", f.Name())
} }
return nil return nil
} }

View File

@ -26,11 +26,6 @@ func main() {
os.Exit(1) 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 // Set up a channel to intercept Ctrl+C for graceful shutdowns
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
@ -43,7 +38,6 @@ func main() {
for a.running { for a.running {
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
} }
fmt.Println("Model has stopped running")
fmt.Println("Done") fmt.Println("Done")
os.Exit(0) os.Exit(0)
} }

View File

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