Skip to content

Commit

Permalink
Added a 'posted' event to TumblrBee
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Mar 6, 2017
1 parent 0d13af3 commit 1e4844f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bees/tumblrbee/tumblrbee.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type TumblrBee struct {
consumerSecret string
token string
tokenSecret string

evchan chan bees.Event
}

// Action triggers the action passed to it.
Expand All @@ -57,7 +59,14 @@ func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {
"state": state})
if err != nil {
mod.LogErrorf("Failed to post text: %v", err)
return outs
}
ev := bees.Event{
Bee: mod.Name(),
Name: "posted",
Options: []bees.Placeholder{},
}
mod.evchan <- ev

case "post_quote":
quote := ""
Expand All @@ -72,14 +81,22 @@ func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {
"state": state})
if err != nil {
mod.LogErrorf("Failed to post quote: %v", err)
return outs
}
ev := bees.Event{
Bee: mod.Name(),
Name: "posted",
Options: []bees.Placeholder{},
}
mod.evchan <- ev

case "follow":
blogname := ""
action.Options.Bind("blogname", &blogname)

if err := mod.client.Follow(blogname); err != nil {
mod.LogErrorf("Failed to follow blog: %v", err)
return outs
}

case "unfollow":
Expand All @@ -88,6 +105,7 @@ func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {

if err := mod.client.Unfollow(blogname); err != nil {
mod.LogErrorf("Failed to unfollow blog: %v", err)
return outs
}

default:
Expand All @@ -97,6 +115,16 @@ func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {
return outs
}

// Run executes the Bee's event loop.
func (mod *TumblrBee) Run(eventChan chan bees.Event) {
mod.evchan = eventChan

select {
case <-mod.SigChan:
return
}
}

// ReloadOptions parses the config options and initializes the Bee.
func (mod *TumblrBee) ReloadOptions(options bees.BeeOptions) {
mod.SetOptions(options)
Expand Down
13 changes: 13 additions & 0 deletions bees/tumblrbee/tumblrbeefactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ func (factory *TumblrBeeFactory) Options() []bees.BeeOptionDescriptor {
return opts
}

// Events describes the available events provided by this Bee.
func (factory *TumblrBeeFactory) Events() []bees.EventDescriptor {
events := []bees.EventDescriptor{
{
Namespace: factory.Name(),
Name: "posted",
Description: "is triggered when you posted something",
Options: []bees.PlaceholderDescriptor{},
},
}
return events
}

// Actions describes the available actions provided by this Bee.
func (factory *TumblrBeeFactory) Actions() []bees.ActionDescriptor {
actions := []bees.ActionDescriptor{
Expand Down

0 comments on commit 1e4844f

Please sign in to comment.