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')
|
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()
|
||||||
|
@ -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,7 +34,16 @@ 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 {
|
||||||
return err
|
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.IncomingSlackMessages = make(chan *slack.MessageEvent, 50)
|
||||||
m.OtherRTMEvents = make(chan *slack.RTMEvent, 50)
|
m.OtherRTMEvents = make(chan *slack.RTMEvent, 50)
|
||||||
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user