Make sure we request all required data

This commit is contained in:
Brian Buller 2019-11-22 12:50:34 -06:00
parent 86c0efaff7
commit 8d840d942b
2 changed files with 28 additions and 7 deletions

View File

@ -63,12 +63,6 @@ func (a *App) initialize() error {
slackToken, _ = reader.ReadString('\n') slackToken, _ = reader.ReadString('\n')
a.m.setSlackToken(strings.TrimSpace(slackToken)) a.m.setSlackToken(strings.TrimSpace(slackToken))
} }
slackDMid, err = a.m.GetSlackAdminDMId()
if err != nil || slackDMid == "" {
fmt.Print("Slack Admin DM ID: ")
slackDMid, _ = reader.ReadString('\n')
a.m.setSlackAdminDMId(strings.TrimSpace(slackDMid))
}
go a.watchMessageChannel() go a.watchMessageChannel()
go a.watchRTMEventChannel() go a.watchRTMEventChannel()

View File

@ -1,8 +1,11 @@
package main package main
import ( import (
"bufio"
"errors" "errors"
"fmt" "fmt"
"os"
"strings"
"time" "time"
"github.com/nlopes/slack" "github.com/nlopes/slack"
@ -31,8 +34,17 @@ func (m *BotModel) NewSlack() error {
var err error var err error
m.slackApiToken, err = m.getSlackToken() m.slackApiToken, err = m.getSlackToken()
if err != nil { if err != nil {
if strings.HasPrefix(err.Error(), "Couldn't find") {
m.RequestSlackToken()
} else {
return err return err
} }
}
var slackDMid string
slackDMid, err = m.GetSlackAdminDMId()
if err != nil || slackDMid == "" {
m.RequestAdminDMId()
}
m.IncomingSlackMessages = make(chan *slack.MessageEvent, 50) m.IncomingSlackMessages = make(chan *slack.MessageEvent, 50)
m.OtherRTMEvents = make(chan *slack.RTMEvent, 50) m.OtherRTMEvents = make(chan *slack.RTMEvent, 50)
m.slackApi = slack.New(m.slackApiToken) m.slackApi = slack.New(m.slackApiToken)
@ -44,6 +56,21 @@ func (m *BotModel) NewSlack() error {
return nil return nil
} }
func (m *BotModel) RequestAdminDMId() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Slack Admin DM ID: ")
dmId, _ := reader.ReadString('\n')
m.setSlackAdminDMId(strings.TrimSpace(dmId))
}
func (m *BotModel) RequestSlackToken() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Slack Token: ")
token, _ := reader.ReadString('\n')
m.slackApiToken = strings.TrimSpace(token)
m.setSlackToken(m.slackApiToken)
}
func (m *BotModel) HandleRTMEvents() { func (m *BotModel) HandleRTMEvents() {
for msg := range m.slackRTM.IncomingEvents { for msg := range m.slackRTM.IncomingEvents {
switch ev := msg.Data.(type) { switch ev := msg.Data.(type) {