repo
stringlengths 5
67
| sha
stringlengths 40
40
| path
stringlengths 4
234
| url
stringlengths 85
339
| language
stringclasses 6
values | split
stringclasses 3
values | doc
stringlengths 3
51.2k
| sign
stringlengths 5
8.01k
| problem
stringlengths 13
51.2k
| output
stringlengths 0
3.87M
|
---|---|---|---|---|---|---|---|---|---|
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pastebinbee/pastebinbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pastebinbee/pastebinbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *PastebinBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *PastebinBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := PastebinBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pastebinbee/pastebinbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pastebinbee/pastebinbeefactory.go#L68-L77 | go | train | // Options returns the options available to configure this Bee. | func (factory *PastebinBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *PastebinBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "api_dev_key",
Description: "Developer key for Pastebin API",
Type: "string",
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/htmlextractbee/htmlextractbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/htmlextractbee/htmlextractbee.go#L42-L107 | go | train | // Action triggers the action passed to it. | func (mod *HTMLExtractBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *HTMLExtractBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "extract":
var url string
action.Options.Bind("url", &url)
if start := strings.Index(url, "http"); start >= 0 {
url = url[start:]
if end := strings.Index(url, " "); end >= 0 {
url = url[:end]
}
}
g := goose.New()
article, _ := g.ExtractFromURL(url)
article.Title = strings.TrimSpace(strings.Replace(article.TitleUnmodified, "\n", " ", -1))
if strings.HasPrefix(article.TopImage, "http://data:image") {
article.TopImage = ""
}
if len(article.Title) > 0 {
ev := bees.Event{
Bee: mod.Name(),
Name: "info_extracted",
Options: []bees.Placeholder{
{
Name: "title",
Type: "string",
Value: article.Title,
},
{
Name: "domain",
Type: "string",
Value: article.Domain,
},
{
Name: "top_image",
Type: "url",
Value: article.TopImage,
},
{
Name: "final_url",
Type: "url",
Value: article.FinalURL,
},
{
Name: "meta_description",
Type: "string",
Value: article.MetaDescription,
},
{
Name: "meta_keywords",
Type: "string",
Value: article.MetaKeywords,
},
},
}
mod.evchan <- ev
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/execbee/execbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/execbee/execbeefactory.go#L36-L43 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *ExecBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *ExecBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := ExecBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/timebee/timebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/timebee/timebee.go#L92-L105 | go | train | // Run executes the Bee's event loop. | func (mod *TimeBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *TimeBee) Run(eventChan chan bees.Event) | {
mod.eventChan = eventChan
for {
select {
case <-mod.SigChan:
return
default:
}
mod.timer()
time.Sleep(500 * time.Millisecond)
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/timebee/timebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/timebee/timebee.go#L108-L118 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *TimeBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *TimeBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("second", &mod.second)
options.Bind("minute", &mod.minute)
options.Bind("hour", &mod.hour)
options.Bind("day_of_week", &mod.dayofweek)
options.Bind("day_of_month", &mod.dayofmonth)
options.Bind("month", &mod.month)
options.Bind("year", &mod.year)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/anelpowerctrlbee/anelpowerctrlbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/anelpowerctrlbee/anelpowerctrlbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *AnelPowerCtrlBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *AnelPowerCtrlBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := AnelPowerCtrlBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/filters.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/filters.go#L38-L49 | go | train | // execFilter executes a filter. Returns whether the filter passed or not. | func execFilter(filter string, opts map[string]interface{}) bool | // execFilter executes a filter. Returns whether the filter passed or not.
func execFilter(filter string, opts map[string]interface{}) bool | {
f := *filters.GetFilter("template")
log.Println("\tExecuting filter:", filter)
defer func() {
if e := recover(); e != nil {
log.Println("Fatal filter event:", e)
}
}()
return f.Passes(opts, filter)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbee.go#L53-L116 | go | train | // Action triggers the action passed to it. | func (mod *IrcBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *IrcBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
var sendFunc func(t, msg string)
switch action.Name {
case "notice":
sendFunc = mod.client.Notice
fallthrough
case "send":
if sendFunc == nil {
sendFunc = mod.client.Privmsg
}
tos := []string{}
text := ""
action.Options.Bind("text", &text)
for _, opt := range action.Options {
if opt.Name == "channel" {
tos = append(tos, opt.Value.(string))
}
}
for _, recv := range tos {
if recv == "*" {
// special: send to all joined channels
for _, to := range mod.channels {
sendFunc(to, text)
}
} else {
// needs stripping hostname when sending to user!host
if strings.Index(recv, "!") > 0 {
recv = recv[0:strings.Index(recv, "!")]
}
sendFunc(recv, text)
}
}
case "join":
for _, opt := range action.Options {
if opt.Name == "channel" {
mod.join(opt.Value.(string))
}
}
case "part":
for _, opt := range action.Options {
if opt.Name == "channel" {
mod.part(opt.Value.(string))
}
}
case "kick":
var c, n, m string
action.Options.Bind("channel", &c)
action.Options.Bind("user", &n)
action.Options.Bind("message", &m)
mod.client.Kick(c, n, m)
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbee.go#L176-L303 | go | train | // Run executes the Bee's event loop. | func (mod *IrcBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *IrcBee) Run(eventChan chan bees.Event) | {
if len(mod.server) == 0 {
return
}
// channel signaling IRC connection status
mod.connectedState = make(chan bool)
// setup IRC client:
cfg := irc.NewConfig(mod.nick, "beehive", "beehive")
cfg.SSL = mod.ssl
if mod.ssl {
h, _, _ := net.SplitHostPort(mod.server)
if h == "" {
h = mod.server
}
cfg.SSLConfig = &tls.Config{ServerName: h}
}
cfg.Server = mod.server
cfg.Pass = mod.password
cfg.NewNick = func(n string) string { return n + "_" }
mod.client = irc.Client(cfg)
mod.client.HandleFunc("connected", func(conn *irc.Conn, line *irc.Line) {
mod.connectedState <- true
})
mod.client.HandleFunc("disconnected", func(conn *irc.Conn, line *irc.Line) {
mod.connectedState <- false
})
mod.client.HandleFunc("JOIN", func(conn *irc.Conn, line *irc.Line) {
mod.statusChange(eventChan, conn, line)
})
mod.client.HandleFunc("PART", func(conn *irc.Conn, line *irc.Line) {
mod.statusChange(eventChan, conn, line)
})
mod.client.HandleFunc("QUIT", func(conn *irc.Conn, line *irc.Line) {
mod.statusChange(eventChan, conn, line)
})
mod.client.HandleFunc("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
channel := line.Args[0]
if channel == mod.client.Config().Me.Nick {
channel = line.Src // replies go via PM too
}
msg := ""
if len(line.Args) > 1 {
msg = line.Args[1]
}
user := line.Src[:strings.Index(line.Src, "!")]
hostmask := line.Src[strings.Index(line.Src, "!")+2:]
ev := bees.Event{
Bee: mod.Name(),
Name: "message",
Options: []bees.Placeholder{
{
Name: "channel",
Type: "string",
Value: channel,
},
{
Name: "user",
Type: "string",
Value: user,
},
{
Name: "hostmask",
Type: "string",
Value: hostmask,
},
{
Name: "text",
Type: "string",
Value: msg,
},
},
}
eventChan <- ev
})
waitForDisconnect := false
connecting := false
connected := false
mod.ContextSet("connected", &connected)
for {
// loop on IRC connection events
if !connected {
if waitForDisconnect {
return
}
if !connecting {
connecting = true
mod.Logln("Connecting to IRC:", mod.server)
err := mod.client.Connect()
if err != nil {
mod.LogErrorf("Failed to connect to IRC: %s %v", mod.server, err)
connecting = false
}
}
}
select {
case status := <-mod.connectedState:
if status {
mod.Logln("Connected to IRC:", mod.server)
connecting = false
connected = true
mod.rejoin()
} else {
mod.Logln("Disconnected from IRC:", mod.server)
connecting = false
connected = false
}
case <-mod.SigChan:
if !waitForDisconnect {
mod.client.Quit()
}
waitForDisconnect = true
default:
time.Sleep(time.Second)
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbee.go#L306-L316 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *IrcBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *IrcBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.server)
options.Bind("nick", &mod.nick)
options.Bind("password", &mod.password)
options.Bind("ssl", &mod.ssl)
options.Bind("channels", &mod.channels)
mod.ContextSet("channels", &mod.channels)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/rssbee/rssbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/rssbee/rssbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *RSSBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *RSSBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := RSSBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/jabberbee/jabberbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/jabberbee/jabberbee.go#L45-L62 | go | train | // Action triggers the action passed to it. | func (mod *JabberBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *JabberBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
chat := xmpp.Chat{Type: "chat"}
action.Options.Bind("user", &chat.Remote)
action.Options.Bind("text", &chat.Text)
mod.client.Send(chat)
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/jabberbee/jabberbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/jabberbee/jabberbee.go#L101-L134 | go | train | // Run executes the Bee's event loop. | func (mod *JabberBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *JabberBee) Run(eventChan chan bees.Event) | {
if len(mod.server) == 0 {
return
}
options := xmpp.Options{
Host: mod.server,
User: mod.user,
Password: mod.password,
NoTLS: mod.notls,
Debug: false,
}
var err error
mod.client, err = options.NewClient()
if err != nil {
mod.LogErrorf("Connection error: %s", err)
return
}
defer mod.client.Close()
go func() {
for {
if err := mod.handleEvents(eventChan); err != nil {
return
}
}
}()
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/jabberbee/jabberbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/jabberbee/jabberbee.go#L137-L144 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *JabberBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *JabberBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.server)
options.Bind("user", &mod.user)
options.Bind("password", &mod.password)
options.Bind("notls", &mod.notls)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/facebookbee/facebookbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/facebookbee/facebookbeefactory.go#L43-L50 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *FacebookBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *FacebookBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := FacebookBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/facebookbee/facebookbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/facebookbee/facebookbeefactory.go#L78-L94 | go | train | // OAuth2AccessToken returns the oauth2 access token. | func (factory *FacebookBeeFactory) OAuth2AccessToken(id, secret, code string) (*oauth2.Token, error) | // OAuth2AccessToken returns the oauth2 access token.
func (factory *FacebookBeeFactory) OAuth2AccessToken(id, secret, code string) (*oauth2.Token, error) | {
// Get facebook access token.
conf := &oauth2.Config{
ClientID: id,
ClientSecret: secret,
RedirectURL: api.CanonicalURL().String() + "/" + path.Join("oauth2", factory.ID(), id, secret),
Scopes: []string{"public_profile", "publish_actions"},
Endpoint: oauth2fb.Endpoint,
}
token, err := conf.Exchange(oauth2.NoContext, code)
if err != nil {
fmt.Println("Error:", err)
return nil, err
}
return token, nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/facebookbee/facebookbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/facebookbee/facebookbeefactory.go#L97-L135 | go | train | // Options returns the options available to configure this Bee. | func (factory *FacebookBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *FacebookBeeFactory) Options() []bees.BeeOptionDescriptor | {
conf := &oauth2.Config{
ClientID: "__client_id__",
ClientSecret: "__client_secret__",
RedirectURL: api.CanonicalURL().String() + "/" + path.Join("oauth2", factory.ID(), "__client_id__", "__client_secret__"),
Scopes: []string{"public_profile", "publish_actions"},
Endpoint: oauth2fb.Endpoint,
}
u, err := url.Parse(conf.Endpoint.AuthURL)
if err != nil {
log.Fatal("Parse:", err)
}
parameters := url.Values{}
parameters.Add("client_id", conf.ClientID)
parameters.Add("scope", strings.Join(conf.Scopes, " "))
parameters.Add("redirect_uri", conf.RedirectURL)
parameters.Add("response_type", "code")
parameters.Add("state", "beehive")
u.RawQuery = parameters.Encode()
opts := []bees.BeeOptionDescriptor{
{
Name: "client_id",
Description: "App ID for the Facebook API",
Type: "string",
},
{
Name: "client_secret",
Description: "App Secret for the Facebook API",
Type: "string",
},
{
Name: "access_token",
Description: "Access token for the Facebook API",
Type: "oauth2:" + u.String(),
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/openweathermapbee/event.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/openweathermapbee/event.go#L31-L183 | go | train | // TriggerCurrentWeatherEvent triggers all current weather events | func (mod *OpenweathermapBee) TriggerCurrentWeatherEvent() | // TriggerCurrentWeatherEvent triggers all current weather events
func (mod *OpenweathermapBee) TriggerCurrentWeatherEvent() | {
ev := bees.Event{
Bee: mod.Name(),
Name: "current_weather",
Options: []bees.Placeholder{
{
Name: "geo_pos_longitude",
Type: "float64",
Value: mod.current.GeoPos.Longitude,
},
{
Name: "geo_pos_latitude",
Type: "float64",
Value: mod.current.GeoPos.Latitude,
},
{
Name: "sys_type",
Type: "int",
Value: mod.current.Sys.Type,
},
{
Name: "sys_id",
Type: "int",
Value: mod.current.Sys.ID,
},
{
Name: "sys_message",
Type: "float64",
Value: mod.current.Sys.Message,
},
{
Name: "sys_country",
Type: "string",
Value: mod.current.Sys.Country,
},
{
Name: "sys_sunrise",
Type: "int",
Value: mod.current.Sys.Sunrise,
},
{
Name: "sys_sunset",
Type: "int",
Value: mod.current.Sys.Sunset,
},
{
Name: "base",
Type: "string",
Value: mod.current.Base,
},
{
Name: "main_temp",
Type: "float64",
Value: mod.current.Main.Temp,
},
{
Name: "main_temp_min",
Type: "float64",
Value: mod.current.Main.TempMin,
},
{
Name: "main_temp_max",
Type: "float64",
Value: mod.current.Main.TempMax,
},
{
Name: "main_pressure",
Type: "float64",
Value: mod.current.Main.Pressure,
},
{
Name: "main_sealevel",
Type: "float64",
Value: mod.current.Main.SeaLevel,
},
{
Name: "main_grndlevel",
Type: "float64",
Value: mod.current.Main.GrndLevel,
},
{
Name: "main_humidity",
Type: "float64",
Value: mod.current.Main.Humidity,
},
{
Name: "wind_speed",
Type: "float64",
Value: mod.current.Wind.Speed,
},
{
Name: "wind_deg",
Type: "float64",
Value: mod.current.Wind.Deg,
},
{
Name: "clouds_all",
Type: "int",
Value: mod.current.Clouds.All,
},
{
Name: "rain",
Type: "map[string]float64",
Value: mod.current.Rain,
},
{
Name: "snow",
Type: "map[string]float64",
Value: mod.current.Snow,
},
{
Name: "dt",
Type: "int",
Value: mod.current.Dt,
},
{
Name: "id",
Type: "int",
Value: mod.current.ID,
},
{
Name: "name",
Type: "string",
Value: mod.current.Name,
},
{
Name: "cod",
Type: "int",
Value: mod.current.Cod,
},
{
Name: "unit",
Type: "string",
Value: mod.current.Unit,
},
{
Name: "lang",
Type: "string",
Value: mod.current.Lang,
},
{
Name: "key",
Type: "string",
Value: mod.current.Key,
},
},
}
mod.evchan <- ev
for _, v := range mod.current.Weather {
mod.TriggerWeatherInformationEvent(&v)
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/openweathermapbee/event.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/openweathermapbee/event.go#L186-L214 | go | train | // WeatherInformationEvent triggers a weather event | func (mod *OpenweathermapBee) TriggerWeatherInformationEvent(v *owm.Weather) | // WeatherInformationEvent triggers a weather event
func (mod *OpenweathermapBee) TriggerWeatherInformationEvent(v *owm.Weather) | {
weather := bees.Event{
Bee: mod.Name(),
Name: "main_weather",
Options: []bees.Placeholder{
{
Name: "id",
Type: "int",
Value: v.ID,
},
{
Name: "main",
Type: "string",
Value: v.Main,
},
{
Name: "description",
Type: "string",
Value: v.Description,
},
{
Name: "icon",
Type: "string",
Value: v.Icon,
},
},
}
mod.evchan <- weather
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/spaceapibee/spaceapibeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/spaceapibee/spaceapibeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *SpaceAPIBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *SpaceAPIBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := SpaceAPIBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/spaceapibee/spaceapibeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/spaceapibee/spaceapibeefactory.go#L81-L91 | go | train | // Actions describes the available actions provided by this Bee. | func (factory *SpaceAPIBeeFactory) Actions() []bees.ActionDescriptor | // Actions describes the available actions provided by this Bee.
func (factory *SpaceAPIBeeFactory) Actions() []bees.ActionDescriptor | {
actions := []bees.ActionDescriptor{
{
Namespace: factory.Name(),
Name: "status",
Description: "Gets the Status of a LabAPI instance",
Options: []bees.PlaceholderDescriptor{},
},
}
return actions
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/spaceapibee/spaceapibeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/spaceapibee/spaceapibeefactory.go#L94-L110 | go | train | // Events describes the available events provided by this Bee. | func (factory *SpaceAPIBeeFactory) Events() []bees.EventDescriptor | // Events describes the available events provided by this Bee.
func (factory *SpaceAPIBeeFactory) Events() []bees.EventDescriptor | {
events := []bees.EventDescriptor{
{
Namespace: factory.Name(),
Name: "result",
Description: "is triggered as soon as the query has been executed",
Options: []bees.PlaceholderDescriptor{
{
Name: "open",
Description: "open-state of the spaceapi instance that was queried",
Type: "bool",
},
},
},
}
return events
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cronbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cronbee.go#L41-L64 | go | train | // Run executes the Bee's event loop. | func (mod *CronBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *CronBee) Run(eventChan chan bees.Event) | {
mod.eventChan = eventChan
timer := cron.ParseInput(mod.input)
for {
select {
case <-mod.SigChan:
return
case <-time.After(timer.DurationUntilNextEvent()):
event := bees.Event{
Bee: mod.Name(),
Name: "time",
Options: []bees.Placeholder{
{
Name: "timestamp",
Type: "string",
Value: timer.GetNextEvent(),
},
},
}
mod.eventChan <- event
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cronbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cronbee.go#L67-L76 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *CronBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *CronBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("second", &mod.input[0])
options.Bind("minute", &mod.input[1])
options.Bind("hour", &mod.input[2])
options.Bind("day_of_week", &mod.input[3])
options.Bind("day_of_month", &mod.input[4])
options.Bind("month", &mod.input[5])
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/jabberbee/jabberbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/jabberbee/jabberbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *JabberBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *JabberBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := JabberBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/tumblrbee/tumblrbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/tumblrbee/tumblrbee.go#L48-L116 | go | train | // Action triggers the action passed to it. | func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "post_text":
text := ""
action.Options.Bind("text", &text)
state := "published"
err := mod.client.CreateText(mod.blogname, map[string]string{
"body": text,
"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 := ""
source := ""
action.Options.Bind("quote", "e)
action.Options.Bind("source", &source)
state := "published"
err := mod.client.CreateQuote(mod.blogname, map[string]string{
"quote": quote,
"source": source,
"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":
blogname := ""
action.Options.Bind("blogname", &blogname)
if err := mod.client.Unfollow(blogname); err != nil {
mod.LogErrorf("Failed to unfollow blog: %v", err)
return outs
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/tumblrbee/tumblrbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/tumblrbee/tumblrbee.go#L119-L126 | go | train | // Run executes the Bee's event loop. | func (mod *TumblrBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *TumblrBee) Run(eventChan chan bees.Event) | {
mod.evchan = eventChan
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/tumblrbee/tumblrbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/tumblrbee/tumblrbee.go#L129-L142 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *TumblrBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *TumblrBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("blogname", &mod.blogname)
options.Bind("callback_url", &mod.callbackURL)
options.Bind("consumer_key", &mod.consumerKey)
options.Bind("consumer_secret", &mod.consumerSecret)
options.Bind("token", &mod.token)
options.Bind("token_secret", &mod.tokenSecret)
mod.client = gotumblr.NewTumblrRestClient(mod.consumerKey, mod.consumerSecret,
mod.token, mod.tokenSecret,
mod.callbackURL, "http://api.tumblr.com")
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | filters/template/templatefilter.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/filters/template/templatefilter.go#L48-L70 | go | train | // Passes returns true when the Filter matched the data. | func (filter *TemplateFilter) Passes(data interface{}, value interface{}) bool | // Passes returns true when the Filter matched the data.
func (filter *TemplateFilter) Passes(data interface{}, value interface{}) bool | {
switch v := value.(type) {
case string:
var res bytes.Buffer
if strings.Index(v, "{{test") >= 0 {
v = strings.Replace(v, "{{test", "{{if", -1)
v += "true{{end}}"
}
tmpl, err := template.New("_" + v).Funcs(templatehelper.FuncMap).Parse(v)
if err == nil {
err = tmpl.Execute(&res, data)
}
if err != nil {
panic(err)
}
return strings.TrimSpace(res.String()) == "true"
}
return false
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/prometheusbee/prometheusbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/prometheusbee/prometheusbeefactory.go#L35-L42 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *PrometheusBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *PrometheusBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := PrometheusBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/prometheusbee/prometheusbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/prometheusbee/prometheusbeefactory.go#L111-L281 | go | train | // Actions describes the available actions provided by this Bee. | func (factory *PrometheusBeeFactory) Actions() []bees.ActionDescriptor | // Actions describes the available actions provided by this Bee.
func (factory *PrometheusBeeFactory) Actions() []bees.ActionDescriptor | {
actions := []bees.ActionDescriptor{
{
Namespace: factory.Name(),
Name: "counter_inc",
Description: "Increments the value of a counter by 1",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the counter to increment",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "counter_add",
Description: "Adds an arbitrary, positive value to a counter",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the counter to add to",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "Value to add to the counter",
Type: "float64",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_set",
Description: "Sets a gauge's value to an arbitrary value",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to set",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "New value for the gauge",
Type: "float64",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_inc",
Description: "Increments the value of a gauge by 1",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to increment",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_dec",
Description: "Decrements the value of a gauge by 1",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to decrement",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_add",
Description: "Adds an arbitrary value to a gauge",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to add to",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "Value to add to the counter",
Type: "float64",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_sub",
Description: "Subtracts an arbitrary value from a gauge",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to subtract from",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "Value to subtract from the gauge",
Type: "float64",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "gauge_set_to_current_time",
Description: "Sets a gauge's value to the current time as a unix timestamp",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the gauge to set",
Type: "string",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "histogram_observe",
Description: "Records an observation in a histogram",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the histogram to add an observation to",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "Value to observe",
Type: "float64",
Mandatory: true,
},
},
},
{
Namespace: factory.Name(),
Name: "summary_observe",
Description: "Records an observation in a summary",
Options: []bees.PlaceholderDescriptor{
{
Name: "label",
Description: "Label of the summary to add an observation to",
Type: "string",
Mandatory: true,
},
{
Name: "value",
Description: "Value to observe",
Type: "float64",
Mandatory: true,
},
},
},
}
return actions
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/hives/hives_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/hives/hives_response.go#L56-L61 | go | train | // Init a new response | func (r *HiveResponse) Init(context smolder.APIContext) | // Init a new response
func (r *HiveResponse) Init(context smolder.APIContext) | {
r.Parent = r
r.Context = context
r.hives = make(map[string]*bees.BeeFactoryInterface)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/hives/hives_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/hives/hives_response.go#L64-L66 | go | train | // AddHive adds a hive to the response | func (r *HiveResponse) AddHive(hive *bees.BeeFactoryInterface) | // AddHive adds a hive to the response
func (r *HiveResponse) AddHive(hive *bees.BeeFactoryInterface) | {
r.hives[(*hive).Name()] = hive
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/hives/hives_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/hives/hives_response.go#L69-L81 | go | train | // Send responds to a request with http.StatusOK | func (r *HiveResponse) Send(response *restful.Response) | // Send responds to a request with http.StatusOK
func (r *HiveResponse) Send(response *restful.Response) | {
var keys []string
for k := range r.hives {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
r.Hives = append(r.Hives, PrepareHiveResponse(r.Context, r.hives[k]))
}
r.Response.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/hives/hives_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/hives/hives_response.go#L84-L93 | go | train | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with | func (r *HiveResponse) EmptyResponse() interface{} | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *HiveResponse) EmptyResponse() interface{} | {
if len(r.hives) == 0 {
var out struct {
Hives interface{} `json:"hives"`
}
out.Hives = []HiveInfoResponse{}
return out
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_response.go#L57-L63 | go | train | // Init a new response | func (r *BeeResponse) Init(context smolder.APIContext) | // Init a new response
func (r *BeeResponse) Init(context smolder.APIContext) | {
r.Parent = r
r.Context = context
r.bees = make(map[string]*bees.BeeInterface)
r.hives = make(map[string]*bees.BeeFactoryInterface)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_response.go#L66-L76 | go | train | // AddBee adds a bee to the response | func (r *BeeResponse) AddBee(bee *bees.BeeInterface) | // AddBee adds a bee to the response
func (r *BeeResponse) AddBee(bee *bees.BeeInterface) | {
r.bees[(*bee).Name()] = bee
hive := bees.GetFactory((*bee).Namespace())
if hive == nil {
panic("Hive for Bee not found")
}
r.hives[(*hive).Name()] = hive
r.Hives = append(r.Hives, hives.PrepareHiveResponse(r.Context, hive))
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_response.go#L79-L91 | go | train | // Send responds to a request with http.StatusOK | func (r *BeeResponse) Send(response *restful.Response) | // Send responds to a request with http.StatusOK
func (r *BeeResponse) Send(response *restful.Response) | {
var keys []string
for k := range r.bees {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
r.Bees = append(r.Bees, prepareBeeResponse(r.Context, r.bees[k]))
}
r.Response.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_response.go#L94-L103 | go | train | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with | func (r *BeeResponse) EmptyResponse() interface{} | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *BeeResponse) EmptyResponse() interface{} | {
if len(r.bees) == 0 {
var out struct {
Bees interface{} `json:"bees"`
}
out.Bees = []beeInfoResponse{}
return out
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/execbee/execbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/execbee/execbee.go#L44-L140 | go | train | // Action triggers the action passed to it. | func (mod *ExecBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *ExecBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "execute":
var command string
var stdin string
action.Options.Bind("command", &command)
action.Options.Bind("stdin", &stdin)
mod.Logln("Executing locally: ", command)
go func() {
c := strings.Split(command, " ")
cmd := exec.Command(c[0], c[1:]...)
if stdin != "" {
stdinPipe, err := cmd.StdinPipe()
if err != nil {
mod.LogFatal("Error creating stdinPipe for Cmd", err)
return
}
go func() {
io.WriteString(stdinPipe, stdin)
stdinPipe.Close()
}()
}
// read and print stdout
outReader, err := cmd.StdoutPipe()
if err != nil {
mod.LogFatal("Error creating StdoutPipe for Cmd", err)
return
}
outBuffer := []string{}
outScanner := bufio.NewScanner(outReader)
go func() {
for outScanner.Scan() {
foo := outScanner.Text()
mod.Logln("execbee: std: | ", foo)
outBuffer = append(outBuffer, foo)
}
}()
// read and print stderr
errReader, err := cmd.StderrPipe()
if err != nil {
mod.LogFatal("Error creating StderrPipe for Cmd", err)
return
}
errBuffer := []string{}
errScanner := bufio.NewScanner(errReader)
go func() {
for errScanner.Scan() {
foo := errScanner.Text()
mod.Logln("Err: | ", foo)
errBuffer = append(errBuffer, foo)
}
}()
err = cmd.Start()
if err != nil {
mod.LogFatal("Error starting Cmd", err)
}
err = cmd.Wait()
if err != nil {
mod.LogFatal("Error waiting for Cmd", err)
}
ev := bees.Event{
Bee: mod.Name(),
Name: "result",
Options: []bees.Placeholder{
{
Name: "stdout",
Type: "string",
Value: strings.Join(outBuffer, "\n"),
},
{
Name: "stderr",
Type: "string",
Value: strings.Join(errBuffer, "\n"),
},
},
}
mod.eventChan <- ev
}()
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pushoverbee/pushoverbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pushoverbee/pushoverbee.go#L48-L89 | go | train | // Action triggers the action passed to it. | func (mod *PushoverBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *PushoverBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
var message, title, nurl, urlTitle string
action.Options.Bind("message", &message)
action.Options.Bind("title", &title)
action.Options.Bind("url", &nurl)
action.Options.Bind("url_title", &urlTitle)
msg := url.Values{}
msg.Set("token", mod.token)
msg.Set("user", mod.userToken)
msg.Set("message", message)
if nurl != "" {
msg.Set("url", nurl)
}
if urlTitle != "" {
msg.Set("url_title", urlTitle)
}
if title != "" {
msg.Set("title", title)
}
mod.Logln(msg)
resp, err := http.PostForm("https://api.pushover.net/1/messages.json", msg)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
mod.Logln("Pushover send message success.")
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pushoverbee/pushoverbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pushoverbee/pushoverbee.go#L92-L96 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *PushoverBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *PushoverBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("token", &mod.token)
options.Bind("user_token", &mod.userToken)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/api.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/api.go#L71-L82 | go | train | // Try to read a local/embedded asset. Gracefully fail and read index.html if
// if not found. | func readAssetOrIndex(path string) (string, []byte, error) | // Try to read a local/embedded asset. Gracefully fail and read index.html if
// if not found.
func readAssetOrIndex(path string) (string, []byte, error) | {
b, err := Asset(path)
if err != nil {
path = "config/index.html"
b, err = Asset(path)
if err != nil {
return path, nil, err
}
}
return path, b, nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/api.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/api.go#L164-L202 | go | train | // Run sets up the restful API container and an HTTP server go-routine | func Run() | // Run sets up the restful API container and an HTTP server go-routine
func Run() | {
// to see what happens in the package, uncomment the following
//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))
// Setup web-service
smolderConfig := smolder.APIConfig{
BaseURL: canonicalURL,
PathPrefix: "v1/",
}
context := &context.APIContext{
Config: smolderConfig,
}
wsContainer := smolder.NewSmolderContainer(smolderConfig, nil, nil)
wsContainer.Router(restful.CurlyRouter{})
ws := new(restful.WebService)
ws.Route(ws.GET("/images/{subpath:*}").To(assetHandler))
ws.Route(ws.GET("/oauth2/{subpath:*}").To(oauth2Handler))
ws.Route(ws.GET("/{subpath:*}").To(assetHandler))
ws.Route(ws.GET("/").To(assetHandler))
wsContainer.Add(ws)
func(resources ...smolder.APIResource) {
for _, r := range resources {
r.Register(wsContainer, smolderConfig, context)
}
}(
&hives.HiveResource{},
&bees.BeeResource{},
&chains.ChainResource{},
&actions.ActionResource{},
&logs.LogResource{},
)
server := &http.Server{Addr: bind, Handler: wsContainer}
go func() {
log.Fatal(server.ListenAndServe())
}()
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mumblebee/mumblebeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mumblebee/mumblebeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *MumbleBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *MumbleBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := MumbleBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/tumblrbee/tumblrbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/tumblrbee/tumblrbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *TumblrBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *TumblrBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := TumblrBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/tumblrbee/tumblrbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/tumblrbee/tumblrbeefactory.go#L68-L108 | go | train | // Options returns the options available to configure this Bee. | func (factory *TumblrBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *TumblrBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "blogname",
Description: "Name of the Tumblr blog",
Type: "string",
Mandatory: true,
},
{
Name: "consumer_key",
Description: "Consumer Key",
Type: "string",
Mandatory: true,
},
{
Name: "consumer_secret",
Description: "Consumer Secret",
Type: "string",
Mandatory: true,
},
{
Name: "token",
Description: "Token",
Type: "string",
Mandatory: true,
},
{
Name: "token_secret",
Description: "Token Secret",
Type: "string",
Mandatory: true,
},
{
Name: "callback_url",
Description: "Callback URL",
Type: "url",
Mandatory: false,
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/githubbee/githubbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/githubbee/githubbeefactory.go#L35-L42 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *GitHubBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *GitHubBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := GitHubBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/githubbee/githubbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/githubbee/githubbeefactory.go#L95-L514 | go | train | // Events describes the available events provided by this Bee. | func (factory *GitHubBeeFactory) Events() []bees.EventDescriptor | // Events describes the available events provided by this Bee.
func (factory *GitHubBeeFactory) Events() []bees.EventDescriptor | {
events := []bees.EventDescriptor{
{
Namespace: factory.Name(),
Name: "push",
Description: "Commits were pushed to a repository",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that something was pushed to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that pushed the commits",
Type: "string",
},
{
Name: "url",
Description: "URL to the diff-view of the changes",
Type: "url",
},
{
Name: "event_id",
Description: "ID of the GitHub event",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "commit",
Description: "New commit in a repository",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that something was committed to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that authored the commit",
Type: "string",
},
{
Name: "url",
Description: "URL to the diff-view of the commit",
Type: "url",
},
{
Name: "id",
Description: "ID of the commit",
Type: "string",
},
{
Name: "message",
Description: "Commit message",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "star",
Description: "Someone starred a repository",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that was starred",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that starred the repository",
Type: "string",
},
{
Name: "event_id",
Description: "ID of the GitHub event",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "fork",
Description: "Someone forked a repository",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that was forked",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that forked the repository",
Type: "string",
},
{
Name: "event_id",
Description: "ID of the GitHub event",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "issue_open",
Description: "An issue was opened",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the issue belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that created the issue",
Type: "string",
},
{
Name: "url",
Description: "URL to the issue on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the issue",
Type: "int",
},
{
Name: "title",
Description: "Issue title",
Type: "string",
},
{
Name: "text",
Description: "Issue text",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "issue_close",
Description: "An issue was closed",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the issue belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that closed the issue",
Type: "string",
},
{
Name: "url",
Description: "URL to the issue on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the issue",
Type: "int",
},
{
Name: "title",
Description: "Issue title",
Type: "string",
},
{
Name: "text",
Description: "Issue text",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "issue_comment",
Description: "An issue was commented on",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the issue belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that commented on the issue",
Type: "string",
},
{
Name: "url",
Description: "URL to the comment on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the issue",
Type: "int",
},
{
Name: "text",
Description: "Issue text",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "pullrequest_open",
Description: "A Pull Request was created",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the Pull Request belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that opened the Pull Request",
Type: "string",
},
{
Name: "url",
Description: "URL to the Pull Request on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the Pull Request",
Type: "int",
},
{
Name: "title",
Description: "Pull Request title",
Type: "string",
},
{
Name: "text",
Description: "Pull Request text",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "pullrequest_close",
Description: "A Pull Request was closed",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the Pull Request belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that closed the Pull Request",
Type: "string",
},
{
Name: "url",
Description: "URL to the Pull Request on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the Pull Request",
Type: "int",
},
{
Name: "title",
Description: "Pull Request title",
Type: "string",
},
{
Name: "text",
Description: "Pull Request text",
Type: "string",
},
},
},
{
Namespace: factory.Name(),
Name: "pullrequest_review_comment",
Description: "A Pull Request commit was commented on",
Options: []bees.PlaceholderDescriptor{
{
Name: "public",
Description: "Indicates whether this was a public activity",
Type: "string",
},
{
Name: "repo",
Description: "The repository that the Pull Request belongs to",
Type: "string",
},
{
Name: "repo_url",
Description: "The repository's URL",
Type: "url",
},
{
Name: "username",
Description: "Username that commented on the Pull Request commit",
Type: "string",
},
{
Name: "url",
Description: "URL to the comment on GitHub",
Type: "url",
},
{
Name: "id",
Description: "ID of the Pull Request",
Type: "int",
},
{
Name: "text",
Description: "Review text",
Type: "string",
},
},
},
}
return events
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/huebee/huebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/huebee/huebee.go#L44-L113 | go | train | // Action triggers the action passed to it. | func (mod *HueBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *HueBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "setcolor":
var lightID int
var color string
brightness := 254
action.Options.Bind("light", &lightID)
action.Options.Bind("color", &color)
action.Options.Bind("brightness", &brightness)
light, err := mod.client.FindLightById(strconv.Itoa(lightID))
if err != nil {
panic(err)
}
state := hue.SetLightState{
On: "true",
Bri: strconv.FormatInt(int64(brightness), 10),
Sat: "254",
}
switch strings.ToLower(color) {
case "coolwhite":
state.Ct = strconv.FormatInt(150, 10)
state.Sat = ""
case "warmwhite":
state.Ct = strconv.FormatInt(500, 10)
state.Sat = ""
case "green":
state.Hue = strconv.FormatInt(182*140, 10)
case "red":
state.Hue = strconv.FormatInt(0, 10)
case "blue":
state.Hue = strconv.FormatInt(182*250, 10)
case "orange":
state.Hue = strconv.FormatInt(182*25, 10)
case "yellow":
state.Hue = strconv.FormatInt(182*85, 10)
case "pink":
state.Hue = strconv.FormatInt(182*300, 10)
case "purple":
state.Hue = strconv.FormatInt(182*270, 10)
}
light.SetState(state)
case "switch":
var lightId int
var state bool
action.Options.Bind("light", &lightId)
action.Options.Bind("state", &state)
light, err := mod.client.FindLightById(strconv.Itoa(lightId))
if err != nil {
panic(err)
}
if state {
light.On()
} else {
light.Off()
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/huebee/huebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/huebee/huebee.go#L116-L123 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *HueBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *HueBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.bridge)
options.Bind("key", &mod.key)
mod.client = hue.NewBridge(mod.bridge, mod.key)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/socketbee/socketbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/socketbee/socketbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *SocketBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *SocketBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := SocketBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cronbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cronbeefactory.go#L35-L42 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *CronBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *CronBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := CronBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L52-L54 | go | train | // Returns the time.Duration until the next event. | func (c *crontime) DurationUntilNextEvent() time.Duration | // Returns the time.Duration until the next event.
func (c *crontime) DurationUntilNextEvent() time.Duration | {
return c.nextEvent().Sub(time.Now())
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L93-L106 | go | train | // This functions calculates the next event | func (c *crontime) calculateEvent(baseTime time.Time) time.Time | // This functions calculates the next event
func (c *crontime) calculateEvent(baseTime time.Time) time.Time | {
c.calculationInProgress = true
defer c.setCalculationInProgress(false)
baseTime = setNanoecond(baseTime, 10000)
c.calculatedTime = baseTime // Ignore all Events in the Past & initial 'result'
//c.calculatedTime = setNanoecond(c.calculatedTime, 10000)
c.nextValidMonth(baseTime)
c.nextValidDay(baseTime)
c.nextValidHour(baseTime)
c.nextValidMinute(baseTime)
c.nextValidSecond(baseTime)
log.Println("Cronbee has found a time stamp: ", c.calculatedTime)
return c.calculatedTime
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L109-L123 | go | train | // Calculates the next valid Month based upon the previous results. | func (c *crontime) nextValidMonth(baseTime time.Time) | // Calculates the next valid Month based upon the previous results.
func (c *crontime) nextValidMonth(baseTime time.Time) | {
for _, mon := range c.month {
if mon >= int(c.calculatedTime.Month()) {
//log.Print("Inside Month", mon, c.calculatedTime)
c.calculatedTime = setMonth(c.calculatedTime, mon)
//log.Println(" :: and out", c.calculatedTime)
return
}
}
// If no result was found try it again in the following year
c.calculatedTime = c.calculatedTime.AddDate(1, 0, 0)
c.calculatedTime = setMonth(c.calculatedTime, c.month[0])
//log.Println("Cronbee: Month", c.calculatedTime, baseTime, c.month)
c.nextValidMonth(baseTime)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L126-L152 | go | train | // Calculates the next valid Day based upon the previous results. | func (c *crontime) nextValidDay(baseTime time.Time) | // Calculates the next valid Day based upon the previous results.
func (c *crontime) nextValidDay(baseTime time.Time) | {
for _, dom := range c.dom {
if dom >= c.calculatedTime.Day() {
for _, dow := range c.dow {
if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()) {
c.calculatedTime = setDay(c.calculatedTime, dom)
//log.Println("Cronbee: Day-INS-1:", c.calculatedTime)
return
}
}
}
} /* else {
for _, dow := range c.dow {
if monthHasDow(dow, dom, int(c.calculatedTime.Month()), c.calculatedTime.Year()){
c.calculatedTime = setDay(c.calculatedTime, dom)
log.Println("Cronbee: Day-INS-2:", c.calculatedTime)
return
}
}
}*/
// If no result was found try it again in the following month.
c.calculatedTime = c.calculatedTime.AddDate(0, 1, 0)
c.calculatedTime = setDay(c.calculatedTime, c.dom[0])
//log.Println("Cronbee: Day", c.calculatedTime, baseTime)
c.nextValidMonth(baseTime)
c.nextValidDay(baseTime)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L155-L174 | go | train | // Calculates the next valid Hour based upon the previous results. | func (c *crontime) nextValidHour(baseTime time.Time) | // Calculates the next valid Hour based upon the previous results.
func (c *crontime) nextValidHour(baseTime time.Time) | {
for _, hour := range c.hour {
if c.calculatedTime.Day() == baseTime.Day() {
if !hasPassed(hour, c.calculatedTime.Hour()) {
c.calculatedTime = setHour(c.calculatedTime, hour)
return
}
} else {
c.calculatedTime = setHour(c.calculatedTime, hour)
return
}
}
// If no result was found try it again in the following day.
c.calculatedTime = c.calculatedTime.AddDate(0, 0, 1) // <-|
c.calculatedTime = setHour(c.calculatedTime, c.hour[0]) // |
//log.Println("Cronbee: Hour", c.calculatedTime, baseTime) // |
c.nextValidMonth(baseTime) // May trigger a new month --------|
c.nextValidDay(baseTime)
c.nextValidHour(baseTime)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L177-L194 | go | train | // Calculates the next valid Minute based upon the previous results. | func (c *crontime) nextValidMinute(baseTime time.Time) | // Calculates the next valid Minute based upon the previous results.
func (c *crontime) nextValidMinute(baseTime time.Time) | {
for _, min := range c.minute {
if c.calculatedTime.Hour() == baseTime.Hour() {
if !hasPassed(min, c.calculatedTime.Minute()) {
c.calculatedTime = setMinute(c.calculatedTime, min)
return
}
} else {
c.calculatedTime = setMinute(c.calculatedTime, min)
return
}
}
c.calculatedTime = c.calculatedTime.Add(1 * time.Hour)
c.calculatedTime = setMinute(c.calculatedTime, c.minute[0])
//log.Println("Cronbee: Minute", c.calculatedTime, baseTime)
c.nextValidHour(baseTime)
c.nextValidMinute(baseTime)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L197-L215 | go | train | // Calculates the next valid Second based upon the previous results. | func (c *crontime) nextValidSecond(baseTime time.Time) | // Calculates the next valid Second based upon the previous results.
func (c *crontime) nextValidSecond(baseTime time.Time) | {
for _, sec := range c.second {
if !c.minuteHasPassed(baseTime) {
// check if sec is in the past. <= prevents triggering the same event twice
if sec > c.calculatedTime.Second() {
c.calculatedTime = setSecond(c.calculatedTime, sec)
return
}
} else {
c.calculatedTime = setSecond(c.calculatedTime, sec)
return
}
}
c.calculatedTime = c.calculatedTime.Add(1 * time.Minute)
c.calculatedTime = setSecond(c.calculatedTime, 0)
//log.Println("Cronbee: Second", c.calculatedTime, baseTime)
c.nextValidMinute(baseTime)
c.nextValidSecond(baseTime)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/crontime.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/crontime.go#L271-L319 | go | train | // Check if the combination of day(of month), month and year is the weekday dow. | func monthHasDow(dow, dom, month, year int) bool | // Check if the combination of day(of month), month and year is the weekday dow.
func monthHasDow(dow, dom, month, year int) bool | {
if !monthHasDom(dom, month, year) {
return false
}
Nday := dom % 7
var Nmonth int
switch month {
case 1:
Nmonth = 0
case 2:
Nmonth = 3
case 3:
Nmonth = 3
case 4:
Nmonth = 6
case 5:
Nmonth = 1
case 6:
Nmonth = 4
case 7:
Nmonth = 6
case 8:
Nmonth = 2
case 9:
Nmonth = 5
case 10:
Nmonth = 0
case 11:
Nmonth = 3
case 12:
Nmonth = 5
}
var Nyear int
temp := year % 100
if temp != 0 {
Nyear = (temp + (temp / 4)) % 7
} else {
Nyear = 0
}
Ncent := (3 - ((year / 100) % 4)) * 2
var Nsj int
if isLeapYear(year) {
Nsj = -1
} else {
Nsj = 0
}
W := (Nday + Nmonth + Nyear + Ncent + Nsj) % 7
return dow == W
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/alertoverbee/alertoverbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/alertoverbee/alertoverbeefactory.go#L36-L43 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *AlertOverBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *AlertOverBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := AlertOverBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/slackbee/slackbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/slackbee/slackbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *SlackBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *SlackBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := SlackBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/devrantbee/devrantbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/devrantbee/devrantbee.go#L41-L81 | go | train | // Action triggers the action passed to it. | func (mod *DevrantBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *DevrantBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "surprise":
rant, err := mod.client.Surprise()
if err != nil {
mod.LogErrorf("Failed to fetch surprise rant: %v", err)
}
mod.triggerEvent(rant)
case "weekly":
rants, err := mod.client.WeeklyRants()
if err != nil {
mod.LogErrorf("Failed to fetch weekly rants: %v", err)
}
for _, v := range rants {
mod.triggerEvent(v)
}
case "rant":
limit := 0
action.Options.Bind("limit", &limit)
rants, err := mod.client.Rants("", limit, 0)
if err != nil {
mod.LogErrorf("Failed to fetch rants: %v", err)
}
for i := range rants {
mod.triggerEvent(rants[i])
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/devrantbee/devrantbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/devrantbee/devrantbee.go#L144-L149 | go | train | // Run executes the Bee's event loop. | func (mod *DevrantBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *DevrantBee) Run(eventChan chan bees.Event) | {
mod.evchan = eventChan
// Setting up the client, unfortunately we can't really log in as an user
mod.client = devgorant.New()
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pastebinbee/pastebinbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pastebinbee/pastebinbee.go#L38-L64 | go | train | // Action triggers the action passed to it. | func (mod *PastebinBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *PastebinBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "post":
title := ""
content := ""
expire := ""
exposure := ""
action.Options.Bind("title", &title)
action.Options.Bind("content", &content)
action.Options.Bind("expire", &expire)
action.Options.Bind("exposure", &exposure)
ret, err := mod.client.PasteAnonymous(content, title, "text", expire, exposure)
if err != nil {
mod.LogErrorf("Error occurred during posting to Pastebin: %v", err)
} else {
mod.Logln("Paste URL:", ret)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pastebinbee/pastebinbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pastebinbee/pastebinbee.go#L67-L69 | go | train | // Run executes the Bee's event loop. | func (mod *PastebinBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *PastebinBee) Run(eventChan chan bees.Event) | {
mod.client = pastebin.NewPastebin(mod.apiDevKey)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pastebinbee/pastebinbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pastebinbee/pastebinbee.go#L72-L76 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *PastebinBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *PastebinBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("api_dev_key", &mod.apiDevKey)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/notificationbee/notificationbee_unix.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/notificationbee/notificationbee_unix.go#L31-L45 | go | train | // Run executes the Bee's event loop. | func (mod *NotificationBee) execAction(text string, urgency uint32) | // Run executes the Bee's event loop.
func (mod *NotificationBee) execAction(text string, urgency uint32) | {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
notifier := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := notifier.Call("org.freedesktop.Notifications.Notify", 0, "", uint32(0),
"", "Beehive", text, []string{},
map[string]dbus.Variant{"urgency": dbus.MakeVariant(urgency)}, int32(5000))
if call.Err != nil {
mod.Logln("(" + string(urgency) + ") Failed to print message: " + text)
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/factories.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/factories.go#L45-L47 | go | train | // OAuth2AccessToken returns the oauth2 access token. | func (factory *BeeFactory) OAuth2AccessToken(id, secret, code string) (*oauth2.Token, error) | // OAuth2AccessToken returns the oauth2 access token.
func (factory *BeeFactory) OAuth2AccessToken(id, secret, code string) (*oauth2.Token, error) | {
return nil, errors.New("This Hive does not implement OAuth2")
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/factories.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/factories.go#L118-L125 | go | train | // GetFactory returns the factory with a specific name. | func GetFactory(identifier string) *BeeFactoryInterface | // GetFactory returns the factory with a specific name.
func GetFactory(identifier string) *BeeFactoryInterface | {
factory, ok := factories[identifier]
if ok {
return factory
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/factories.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/factories.go#L128-L135 | go | train | // GetFactories returns all known bee factories. | func GetFactories() []*BeeFactoryInterface | // GetFactories returns all known bee factories.
func GetFactories() []*BeeFactoryInterface | {
r := []*BeeFactoryInterface{}
for _, factory := range factories {
r = append(r, factory)
}
return r
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/htmlextractbee/htmlextractbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/htmlextractbee/htmlextractbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *HTMLExtractBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *HTMLExtractBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := HTMLExtractBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/spaceapibee/spaceapibee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/spaceapibee/spaceapibee.go#L43-L88 | go | train | // Action triggers the action passed to it. | func (mod *SpaceAPIBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *SpaceAPIBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "status":
type SpaceAPIResult struct {
State struct {
Open bool `json:"open"`
} `json:"state"`
}
apiState := new(SpaceAPIResult)
// get json data
resp, err := http.Get(mod.url)
if err != nil {
mod.Logln("Error: SpaceAPI instance @ " + mod.url + " not reachable")
} else {
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(body, apiState)
if err != nil {
mod.Logln("Sorry, couldn't unmarshal the JSON data from SpaceAPI Instance @ " + mod.url)
apiState.State.Open = false
}
}
ev := bees.Event{
Bee: mod.Name(),
Name: "result",
Options: []bees.Placeholder{
{
Name: "open",
Type: "bool",
Value: apiState.State.Open,
},
},
}
mod.evchan <- ev
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/spaceapibee/spaceapibee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/spaceapibee/spaceapibee.go#L96-L100 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *SpaceAPIBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *SpaceAPIBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("url", &mod.url)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/devrantbee/devrantbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/devrantbee/devrantbeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *DevrantBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *DevrantBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := DevrantBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/fsnotifybee/fsnotifybeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/fsnotifybee/fsnotifybeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *FSNotifyBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *FSNotifyBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := FSNotifyBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/chains.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L52-L60 | go | train | // GetChain returns a chain with a specific id | func GetChain(id string) *Chain | // GetChain returns a chain with a specific id
func GetChain(id string) *Chain | {
for _, c := range chains {
if c.Name == id {
return &c
}
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/chains.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L63-L84 | go | train | // SetChains sets the currently configured chains | func SetChains(cs []Chain) | // SetChains sets the currently configured chains
func SetChains(cs []Chain) | {
newcs := []Chain{}
// migrate old chain style
for _, c := range cs {
for _, el := range c.Elements {
if el.Action.Name != "" {
el.Action.ID = UUID()
c.Actions = append(c.Actions, el.Action.ID)
actions = append(actions, el.Action)
}
if el.Filter.Name != "" {
//FIXME: migrate old style filters
c.Filters = append(c.Filters, el.Filter.Options.Value.(string))
}
}
c.Elements = []ChainElement{}
newcs = append(newcs, c)
}
chains = newcs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/chains.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/chains.go#L87-L123 | go | train | // execChains executes chains for an event we received | func execChains(event *Event) | // execChains executes chains for an event we received
func execChains(event *Event) | {
for _, c := range chains {
if c.Event.Name != event.Name || c.Event.Bee != event.Bee {
continue
}
m := make(map[string]interface{})
for _, opt := range event.Options {
m[opt.Name] = opt.Value
}
ctx.FillMap(m)
failed := false
log.Println("Executing chain:", c.Name, "-", c.Description)
for _, el := range c.Filters {
if execFilter(el, m) {
log.Println("\t\tPassed filter!")
} else {
log.Println("\t\tDid not pass filter!")
failed = true
break
}
}
if failed {
continue
}
for _, el := range c.Actions {
action := GetAction(el)
if action == nil {
log.Println("\t\tERROR: Unknown action referenced!")
continue
}
execAction(*action, m)
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/logs/logs_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_get.go#L46-L51 | go | train | // GetParams returns the parameters supported by this API endpoint | func (r *LogResource) GetParams() []*restful.Parameter | // GetParams returns the parameters supported by this API endpoint
func (r *LogResource) GetParams() []*restful.Parameter | {
params := []*restful.Parameter{}
params = append(params, restful.QueryParameter("bee", "id of a bee").DataType("string"))
return params
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/logs/logs_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_get.go#L64-L77 | go | train | // GetByIDs sends out all items matching a set of IDs
/*
func (r *LogResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) {
resp := LogResponse{}
resp.Init(ctx)
resp.Send(response)
}
*/
// Get sends out items matching the query parameters | func (r *LogResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | // GetByIDs sends out all items matching a set of IDs
/*
func (r *LogResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) {
resp := LogResponse{}
resp.Init(ctx)
resp.Send(response)
}
*/
// Get sends out items matching the query parameters
func (r *LogResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | {
// ctxapi := ctx.(*context.APIContext)
bee := request.QueryParameter("bee")
resp := LogResponse{}
resp.Init(ctx)
logs := bees.GetLogs(bee)
for _, log := range logs {
resp.AddLog(&log)
}
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/horizonboxbee/horizonboxbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/horizonboxbee/horizonboxbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *HorizonBoxBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *HorizonBoxBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := HorizonBoxBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/telegrambee/telegrambeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *TelegramBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *TelegramBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := TelegramBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/gitterbee/gitterbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/gitterbee/gitterbee.go#L47-L93 | go | train | // Action triggers the actions passed to it. | func (mod *GitterBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the actions passed to it.
func (mod *GitterBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
var room string
var message string
action.Options.Bind("room", &room)
action.Options.Bind("message", &message)
roomID, err := mod.client.GetRoomId(room)
if err != nil {
mod.LogErrorf("Failed to fetch room ID from uri: %v", err)
return outs
}
if _, err = mod.client.SendMessage(roomID, message); err != nil {
mod.LogErrorf("Failed to send message: %v", err)
return outs
}
case "join":
var room string
action.Options.Bind("room", &room)
if err := mod.join(room); err != nil {
mod.LogErrorf("Failed to join room: %v", err)
}
case "leave":
var room string
action.Options.Bind("room", &room)
err := mod.leave(room)
if err != nil {
mod.LogErrorf("Can't leave room: %v", err)
} else {
mod.Logln("Left room:", room)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/gitterbee/gitterbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/gitterbee/gitterbee.go#L96-L119 | go | train | // Run executes the Bee's event loop. | func (mod *GitterBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *GitterBee) Run(eventChan chan bees.Event) | {
mod.eventChan = eventChan
mod.roomChans = make(map[string]chan interface{})
mod.client = gitter.New(mod.accessToken)
user, err := mod.client.GetUser()
if err != nil {
mod.LogErrorf("Failed to fetch current user: %v", err)
return
}
mod.userID = user.ID
for _, room := range mod.rooms {
mod.join(room)
}
select {
case <-mod.SigChan:
for room := range mod.roomChans {
mod.leave(room)
}
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/gitterbee/gitterbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/gitterbee/gitterbee.go#L214-L219 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *GitterBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *GitterBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("access_token", &mod.accessToken)
options.Bind("rooms", &mod.rooms)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_delete.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_delete.go#L45-L61 | go | train | // Delete processes an incoming DELETE request | func (r *BeeResource) Delete(context smolder.APIContext, request *restful.Request, response *restful.Response) | // Delete processes an incoming DELETE request
func (r *BeeResource) Delete(context smolder.APIContext, request *restful.Request, response *restful.Response) | {
resp := BeeResponse{}
resp.Init(context)
id := request.PathParameter("bee-id")
bee := bees.GetBee(id)
if bee == nil {
r.NotFound(request, response)
return
}
go func() {
bees.DeleteBee(bee)
}()
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/githubbee/githubbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/githubbee/githubbee.go#L48-L93 | go | train | // Action triggers the actions passed to it. | func (mod *GitHubBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the actions passed to it.
func (mod *GitHubBee) Action(action bees.Action) []bees.Placeholder | {
ctx := context.Background()
outs := []bees.Placeholder{}
switch action.Name {
case "follow":
var user string
action.Options.Bind("username", &user)
if _, err := mod.client.Users.Follow(ctx, user); err != nil {
mod.LogErrorf("Failed to follow user: %v", err)
}
case "unfollow":
var user string
action.Options.Bind("username", &user)
if _, err := mod.client.Users.Unfollow(ctx, user); err != nil {
mod.LogErrorf("Failed to follow user: %v", err)
}
case "star":
var user string
var repo string
action.Options.Bind("owner", &user)
action.Options.Bind("repository", &repo)
if _, err := mod.client.Activity.Star(ctx, user, repo); err != nil {
mod.LogErrorf("Failed to star repository: %v", err)
}
case "unstar":
var user string
var repo string
action.Options.Bind("owner", &user)
action.Options.Bind("repository", &repo)
if _, err := mod.client.Activity.Unstar(ctx, user, repo); err != nil {
mod.LogErrorf("Failed to unstar repository: %v", err)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/githubbee/githubbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/githubbee/githubbee.go#L96-L118 | go | train | // Run executes the Bee's event loop. | func (mod *GitHubBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *GitHubBee) Run(eventChan chan bees.Event) | {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: mod.accessToken},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
mod.eventChan = eventChan
mod.client = github.NewClient(tc)
since := time.Now() // .Add(-time.Duration(24 * time.Hour))
timeout := time.Duration(time.Second * 10)
for {
select {
case <-mod.SigChan:
return
case <-time.After(timeout):
mod.getRepositoryEvents(mod.owner, mod.repository, since)
}
since = time.Now()
timeout = time.Duration(time.Minute)
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/githubbee/githubbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/githubbee/githubbee.go#L218-L224 | go | train | /*
func (mod *GitHubBee) getNotifications() {
opts := &github.NotificationListOptions{
All: true,
// Participating: true,
ListOptions: github.ListOptions{
PerPage: 10,
},
}
notif, _, err := mod.client.Activity.ListNotifications(opts)
if err != nil {
mod.LogErrorf("Failed to fetch notifications: %v", err)
}
for _, v := range notif {
ev := bees.Event{
Bee: mod.Name(),
Name: "notification",
Options: []bees.Placeholder{
{
Name: "subject_title",
Type: "string",
Value: *v.Subject.Title,
},
{
Name: "subject_type",
Type: "string",
Value: *v.Subject.Type,
},
{
Name: "subject_url",
Type: "url",
Value: *v.Subject.URL,
},
{
Name: "reason",
Type: "string",
Value: *v.Reason,
},
{
Name: "id",
Type: "string",
Value: *v.ID,
},
{
Name: "url",
Type: "url",
Value: *v.URL,
},
},
}
mod.eventChan <- ev
}
}
*/
// ReloadOptions parses the config options and initializes the Bee. | func (mod *GitHubBee) ReloadOptions(options bees.BeeOptions) | /*
func (mod *GitHubBee) getNotifications() {
opts := &github.NotificationListOptions{
All: true,
// Participating: true,
ListOptions: github.ListOptions{
PerPage: 10,
},
}
notif, _, err := mod.client.Activity.ListNotifications(opts)
if err != nil {
mod.LogErrorf("Failed to fetch notifications: %v", err)
}
for _, v := range notif {
ev := bees.Event{
Bee: mod.Name(),
Name: "notification",
Options: []bees.Placeholder{
{
Name: "subject_title",
Type: "string",
Value: *v.Subject.Title,
},
{
Name: "subject_type",
Type: "string",
Value: *v.Subject.Type,
},
{
Name: "subject_url",
Type: "url",
Value: *v.Subject.URL,
},
{
Name: "reason",
Type: "string",
Value: *v.Reason,
},
{
Name: "id",
Type: "string",
Value: *v.ID,
},
{
Name: "url",
Type: "url",
Value: *v.URL,
},
},
}
mod.eventChan <- ev
}
}
*/
// ReloadOptions parses the config options and initializes the Bee.
func (mod *GitHubBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("accesstoken", &mod.accessToken)
options.Bind("owner", &mod.owner)
options.Bind("repository", &mod.repository)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_post.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_post.go#L54-L70 | go | train | // Post processes an incoming POST (create) request | func (r *ActionResource) Post(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | // Post processes an incoming POST (create) request
func (r *ActionResource) Post(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | {
resp := ActionResponse{}
resp.Init(context)
pps := data.(*ActionPostStruct)
action := bees.Action{
ID: bees.UUID(),
Bee: pps.Action.Bee,
Name: pps.Action.Name,
Options: pps.Action.Options,
}
actions := append(bees.GetActions(), action)
bees.SetActions(actions)
resp.AddAction(&action)
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cleverbotbee/cleverbotbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cleverbotbee/cleverbotbeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *CleverbotBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *CleverbotBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := CleverbotBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cleverbotbee/cleverbotbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cleverbotbee/cleverbotbeefactory.go#L69-L91 | go | train | // Options returns the options available to configure this Bee. | func (factory *CleverbotBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *CleverbotBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "api_user",
Description: "Your cleverbot api username",
Type: "string",
Mandatory: true,
},
{
Name: "api_key",
Description: "Your cleverbot api key",
Type: "string",
Mandatory: true,
},
{
Name: "session_nick",
Description: "Optionally set a nickname for the session",
Type: "string",
Mandatory: false,
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/emailbee/emailbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/emailbee/emailbee.go#L43-L88 | go | train | // Action triggers the action passed to it. | func (mod *EmailBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *EmailBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
var from, to, plainText, htmlText, subject string
action.Options.Bind("sender", &from)
action.Options.Bind("recipient", &to)
action.Options.Bind("subject", &subject)
action.Options.Bind("text", &plainText)
action.Options.Bind("html", &htmlText)
m := mail.NewMessage()
if len(from) > 0 {
m.SetHeader("From", from)
} else {
m.SetHeader("From", mod.username)
}
m.SetHeader("To", to)
m.SetHeader("Subject", subject)
if plainText != "" {
m.SetBody("text/plain", plainText)
}
if htmlText != "" {
m.SetBody("text/html", htmlText)
}
host, portstr, err := net.SplitHostPort(mod.server)
if err != nil {
host = mod.server
portstr = "587"
}
port, _ := strconv.Atoi(portstr)
s, _ := mail.NewDialer(host, port, mod.username, mod.password).Dial()
// Send the email.
if err := mail.Send(s, m); err != nil {
panic(err)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/emailbee/emailbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/emailbee/emailbee.go#L91-L97 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *EmailBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *EmailBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("username", &mod.username)
options.Bind("password", &mod.password)
options.Bind("address", &mod.server)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cricketbee/cricketbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cricketbee/cricketbeefactory.go#L33-L39 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *CricketBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *CricketBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := CricketBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cricketbee/cricketbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cricketbee/cricketbeefactory.go#L67-L78 | go | train | // Options returns the options available to configure this Bee. | func (factory *CricketBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *CricketBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "favourite_team",
Default: "Ind",
Description: "Please mention for which team you want to get updates",
Type: "string",
Mandatory: true,
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/timebee/timebeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/timebee/timebeefactory.go#L35-L42 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *TimeBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *TimeBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := TimeBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |