Make sure we request all required data
This commit is contained in:
parent
86c0efaff7
commit
8d840d942b
@ -63,12 +63,6 @@ func (a *App) initialize() error {
|
||||
slackToken, _ = reader.ReadString('\n')
|
||||
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.watchRTMEventChannel()
|
||||
|
@ -1,8 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nlopes/slack"
|
||||
@ -31,8 +34,17 @@ func (m *BotModel) NewSlack() error {
|
||||
var err error
|
||||
m.slackApiToken, err = m.getSlackToken()
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "Couldn't find") {
|
||||
m.RequestSlackToken()
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
var slackDMid string
|
||||
slackDMid, err = m.GetSlackAdminDMId()
|
||||
if err != nil || slackDMid == "" {
|
||||
m.RequestAdminDMId()
|
||||
}
|
||||
m.IncomingSlackMessages = make(chan *slack.MessageEvent, 50)
|
||||
m.OtherRTMEvents = make(chan *slack.RTMEvent, 50)
|
||||
m.slackApi = slack.New(m.slackApiToken)
|
||||
@ -44,6 +56,21 @@ func (m *BotModel) NewSlack() error {
|
||||
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() {
|
||||
for msg := range m.slackRTM.IncomingEvents {
|
||||
switch ev := msg.Data.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user