Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimTheReaper committed Nov 3, 2016
1 parent 2c1ac5a commit 6195648
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
44 changes: 44 additions & 0 deletions defaulthandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ These are automatically loaded to help handle the singularity instance and keep
func addDefaultHandlers(instance *SlackInstance) {
instance.RegisterHandler("message", MessageHandler)
instance.RegisterHandler("message", HandleCommands)

instance.RegisterHandler("bot_added", handleBotAddedEvent)
instance.RegisterHandler("bot_changed", handleBotChangedEvent)
}

// MessageHandler - if this is a message and we have a handler, handle it
Expand All @@ -36,3 +39,44 @@ func HandleCommands(message Message, instance *SlackInstance) {
}
}
}

// handleBotAddedEvent handles when a bot_added event happens. TODO discuss exportation
/*{
"type": "bot_added",
"bot": {
"id": "B024BE7LH",
"name": "hugbot",
"icons": {
"image_48": "https:\/\/slack.com\/path\/to\/hugbot_48.png"
}
}
}*/
func handleBotAddedEvent(botAdded struct {
Bot Bot `json:"bot"`
}, instance *SlackInstance) {
instance.rtmResp.Lock()
defer instance.rtmResp.Unlock()
instance.rtmResp.Bots = append(instance.rtmResp.Bots, botAdded.Bot)
}

/*{
"type": "bot_changed",
"bot": {
"id": "B024BE7LH",
"name": "hugbot",
"icons": {
"image_48": "https:\/\/slack.com\/path\/to\/hugbot_48.png"
}
}
}*/
func handleBotChangedEvent(botChanged struct {
Bot Bot `json:"bot"`
}, instance *SlackInstance) {
instance.rtmResp.Lock()
defer instance.rtmResp.Unlock()
for i := 0; i < len(instance.rtmResp.Bots); i++ {
if instance.rtmResp.Bots[i].ID == botChanged.Bot.ID {
instance.rtmResp.Bots[i] = botChanged.Bot
}
}
}
3 changes: 2 additions & 1 deletion eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func (handler *EventAPIHandler) execute(key string, body []byte, instance *Slack
value := reflect.New(param0).Interface()
err = json.Unmarshal(body, &value)
if err != nil {
fmt.Printf("Error: %v\n", err) //TODO Better Error Handling. //TODO Remove fmt.
fmt.Printf("Error Executing: %v\n", err) //TODO Better Error Handling. //TODO Remove fmt.
fmt.Printf("Body: %v\n", string(body))
return false
}
reflect.ValueOf(function).Call([]reflect.Value{reflect.ValueOf(value).Elem(), reflect.ValueOf(instance)})
Expand Down
2 changes: 1 addition & 1 deletion team.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (instance *SlackInstance) handleChans() {
fmt.Printf("Type: %v\n", slackType)
if slackType != "" {
instance.handlers.execute(slackType, event, instance)
}
} // TODO handle empty types.

case val := <-instance.output: //<-instance.output sends the thing to slack.
thingToSend, err := val.GetInterface()
Expand Down

0 comments on commit 6195648

Please sign in to comment.