I think things are pretty good

This commit is contained in:
2023-12-01 10:57:15 -06:00
parent ff58d1ddf4
commit 0fc78d4b4c
8 changed files with 65 additions and 69 deletions

View File

@@ -24,6 +24,8 @@ type BotModel struct {
messageWatchers map[string]func(msg BotMessage) bool
rtmWatchers map[string]func(event *slack.RTMEvent) bool
Running bool
}
func NewBotModel(debug bool) (*BotModel, error) {
@@ -60,7 +62,9 @@ func (m *BotModel) DebugRTMWatcher(event *slack.RTMEvent) bool {
}
func (m *BotModel) SendMessage(msg BotMessage) {
fmt.Println("Sending:", msg)
if m.debug {
fmt.Println("Sending:", msg)
}
m.messages <- msg
}
@@ -72,11 +76,8 @@ func (m *BotModel) AddRTMWatcher(name string, watcher func(event *slack.RTMEvent
}
func (m *BotModel) ProcessMessageChannel() {
fmt.Println(">> ProcessMessageChannel")
msg := <-m.messages
fmt.Println(">>>> Received Message", msg)
for k, v := range m.messageWatchers {
fmt.Printf(">>>> Message Watcher [%s]\n", k)
for _, v := range m.messageWatchers {
// Pass the message to the watcher
if v != nil && v(msg) {
// if a watcher returns true, the message was consumed
@@ -85,11 +86,8 @@ func (m *BotModel) ProcessMessageChannel() {
}
}
func (m *BotModel) ProcessRTMChannel() {
fmt.Println(">> ProcessRTMChannel")
msg := <-m.otherRTMEvents
fmt.Println(">>>> Received Message", msg)
for k, v := range m.rtmWatchers {
fmt.Printf(">>>> RTM Watcher [%s]\n", k)
for _, v := range m.rtmWatchers {
// Pass the event to the watcher
if v(msg) {
// if a watcher returns true, the message was consumed