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/events.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/events.go#L39-L67 | go | train | // handleEvents handles incoming events and executes matching Chains. | func handleEvents() | // handleEvents handles incoming events and executes matching Chains.
func handleEvents() | {
for {
event, ok := <-eventsIn
if !ok {
log.Println()
log.Println("Stopped event handler!")
break
}
bee := GetBee(event.Bee)
(*bee).LogEvent()
log.Println()
log.Println("Event received:", event.Bee, "/", event.Name, "-", GetEventDescriptor(&event).Description)
for _, v := range event.Options {
log.Println("\tOptions:", v)
}
go func() {
defer func() {
if e := recover(); e != nil {
log.Printf("Fatal chain event: %s %s", e, debug.Stack())
}
}()
execChains(&event)
}()
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mastodonbee/mastodonbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mastodonbee/mastodonbee.go#L50-L81 | go | train | // Action triggers the action passed to it. | func (mod *mastodonBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *mastodonBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "toot":
var text string
action.Options.Bind("text", &text)
// Post status toot on mastodon
status, err := mod.client.PostStatus(context.Background(), &mastodon.Toot{
Status: text,
})
if err != nil {
mod.LogErrorf("Error sending toot: %v", err)
}
// Handle back 'toot_sent' event
ev := bees.Event{
Bee: mod.Name(),
Name: "toot_sent",
Options: []bees.Placeholder{
{
Name: "text",
Value: status.Content,
Type: "string",
},
},
}
mod.evchan <- ev
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mastodonbee/mastodonbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mastodonbee/mastodonbee.go#L84-L114 | go | train | // Run executes the Bee's event loop. | func (mod *mastodonBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *mastodonBee) Run(eventChan chan bees.Event) | {
// Create the new api client
c := mastodon.NewClient(&mastodon.Config{
Server: mod.server,
ClientID: mod.clientID,
ClientSecret: mod.clientSecret,
})
// authorize it
err := c.Authenticate(context.Background(), mod.email, mod.password)
if err != nil {
mod.LogErrorf("Authorization failed, make sure the mastodon credentials are correct: %s", err)
return
}
// try to get user account
acc, err := c.GetAccountCurrentUser(context.Background())
if err != nil {
mod.LogErrorf("Failed to get current user account: %v", err)
}
mod.Logf("Successfully logged in: %s", acc.URL)
// set client
mod.client = c
// set eventchan
mod.evchan = eventChan
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mastodonbee/mastodonbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mastodonbee/mastodonbee.go#L117-L125 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *mastodonBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *mastodonBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("server", &mod.server)
options.Bind("client_id", &mod.clientID)
options.Bind("client_secret", &mod.clientSecret)
options.Bind("email", &mod.email)
options.Bind("password", &mod.password)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/prometheusbee/prometheusbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/prometheusbee/prometheusbee.go#L53-L129 | go | train | // Run executes the Bee's event loop. | func (mod *PrometheusBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *PrometheusBee) Run(eventChan chan bees.Event) | {
// Counter vector registration
mod.counter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: mod.counterVecName,
Help: "Collection of all counter variables being iterated by hives",
},
[]string{"name"},
)
err := prometheus.Register(mod.counter)
if err != nil {
mod.LogErrorf("Error registering counter vector: %v", err)
panic("Unable to start Prometheus due to counter initialization failure")
}
// Gauge vector registration
mod.gauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: mod.gaugeVecName,
Help: "Collection of all gauge variables being iterated by hives",
},
[]string{"name"},
)
err = prometheus.Register(mod.gauge)
if err != nil {
mod.LogErrorf("Error registering gauge vector: %v", err)
panic("Unable to start Prometheus due to gauge initialization failure")
}
// Histogram vector registration
mod.histogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: mod.histogramVecName,
Help: "Collection of all histogram variables being iterated by hives",
},
[]string{"name"},
)
err = prometheus.Register(mod.histogram)
if err != nil {
mod.LogErrorf("Error registering histogram vector: %v", err)
panic("Unable to start Prometheus due to histogram initialization failure")
}
// Summary vector registration
mod.summary = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: mod.summaryVecName,
Help: "Collection of all summary variables being iterated by hives",
},
[]string{"name"},
)
err = prometheus.Register(mod.summary)
if err != nil {
mod.LogErrorf("Error registering summary vector: %v", err)
panic("Unable to start Prometheus due to summary initialization failure")
}
// Now, to serve everything up:
go func() {
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2112", nil)
if err != nil {
mod.LogErrorf("Error running prometheus metric handler: %v", err)
}
}()
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/prometheusbee/prometheusbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/prometheusbee/prometheusbee.go#L132-L242 | go | train | // Action triggers the action passed to it. | func (mod *PrometheusBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *PrometheusBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "counter_inc":
var label string
action.Options.Bind("label", &label)
c, err := mod.counter.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error incrementing counter: %v", err)
} else {
c.Inc()
}
case "counter_add":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
c, err := mod.counter.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error adding to counter: %v", err)
} else {
c.Add(value)
}
case "gauge_set":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error setting gauge: %v", err)
} else {
g.Set(value)
}
case "gauge_inc":
var label string
action.Options.Bind("label", &label)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error incrementing gauge: %v", err)
} else {
g.Inc()
}
case "gauge_dec":
var label string
action.Options.Bind("label", &label)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error decrementing gauge: %v", err)
} else {
g.Dec()
}
case "gauge_add":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error adding to gauge: %v", err)
} else {
g.Add(value)
}
case "gauge_sub":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error subtracting from gauge: %v", err)
} else {
g.Sub(value)
}
case "gauge_set_to_current_time":
var label string
action.Options.Bind("label", &label)
g, err := mod.gauge.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error setting gauge to current time: %v", err)
} else {
g.SetToCurrentTime()
}
case "histogram_observe":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
h, err := mod.histogram.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error observing value for histogram: %v", err)
} else {
h.Observe(value)
}
case "summary_observe":
var label string
var value float64
action.Options.Bind("label", &label)
action.Options.Bind("value", &value)
s, err := mod.summary.GetMetricWithLabelValues(label)
if err != nil {
mod.LogErrorf("Error observing value for summary: %v", err)
} else {
s.Observe(value)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/prometheusbee/prometheusbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/prometheusbee/prometheusbee.go#L245-L253 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *PrometheusBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *PrometheusBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.addr)
options.Bind("counter_vec_name", &mod.counterVecName)
options.Bind("gauge_vec_name", &mod.gaugeVecName)
options.Bind("histogram_vec_name", &mod.histogramVecName)
options.Bind("summary_vec_name", &mod.summaryVecName)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/nagiosbee/nagiosbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/nagiosbee/nagiosbee.go#L167-L173 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *NagiosBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *NagiosBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("url", &mod.url)
options.Bind("user", &mod.user)
options.Bind("password", &mod.password)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/socketbee/socketbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/socketbee/socketbee.go#L40-L47 | go | train | // Run executes the Bee's event loop. | func (mod *SocketBee) Run(cin chan bees.Event) | // Run executes the Bee's event loop.
func (mod *SocketBee) Run(cin chan bees.Event) | {
mod.eventChan = cin
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/socketbee/socketbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/socketbee/socketbee.go#L50-L86 | go | train | // Action triggers the action passed to it. | func (mod *SocketBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *SocketBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
var data string
var addr string
var port int
action.Options.Bind("address", &addr)
action.Options.Bind("port", &port)
action.Options.Bind("data", &data)
switch action.Name {
case "send":
// log.Println("Sending", data, "to", addr, port)
sa, err := net.ResolveUDPAddr("udp", addr+":"+strconv.Itoa(port))
if err != nil {
log.Panicln(err)
}
conn, err := net.DialUDP("udp", nil, sa)
if err != nil {
log.Panicln(err)
}
defer conn.Close()
_, err = conn.Write([]byte(data))
if err != nil {
log.Panicln(err)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | filters/filters.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/filters/filters.go#L46-L53 | go | train | // GetFilter returns a filter with a specific name | func GetFilter(identifier string) *FilterInterface | // GetFilter returns a filter with a specific name
func GetFilter(identifier string) *FilterInterface | {
filter, ok := filters[identifier]
if ok {
return filter
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/openweathermapbee/openweathermapbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/openweathermapbee/openweathermapbeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *OpenweathermapBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *OpenweathermapBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := OpenweathermapBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/openweathermapbee/openweathermapbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/openweathermapbee/openweathermapbeefactory.go#L96-L274 | go | train | // Events describes the available events provided by this Bee. | func (factory *OpenweathermapBeeFactory) Events() []bees.EventDescriptor | // Events describes the available events provided by this Bee.
func (factory *OpenweathermapBeeFactory) Events() []bees.EventDescriptor | {
events := []bees.EventDescriptor{
{
Namespace: factory.Name(),
Name: "current_weather",
Description: "Current weather holds measurement informations",
Options: []bees.PlaceholderDescriptor{
{
Name: "geo_pos_longitude",
Type: "float64",
Description: "Geo position longitude",
},
{
Name: "geo_pos_latitude",
Type: "float64",
Description: "Geo position latitude",
},
{
Name: "sys_type",
Type: "int",
Description: "sys type",
},
{
Name: "sys_id",
Type: "int",
Description: "sys ID",
},
{
Name: "sys_message",
Type: "float64",
Description: "sys message",
},
{
Name: "sys_country",
Type: "string",
Description: "sys country code",
},
{
Name: "sys_sunrise",
Type: "int",
Description: "sys sunrise",
},
{
Name: "sys_sunset",
Type: "int",
Description: "sys sunset",
},
{
Name: "base",
Type: "string",
Description: "current weather base",
},
{
Name: "main_temp",
Type: "float64",
Description: "current main temperature",
},
{
Name: "main_temp_min",
Type: "float64",
Description: "current main minimum temperature",
},
{
Name: "main_temp_max",
Type: "float64",
Description: "current main maximum temperature",
},
{
Name: "main_pressure",
Type: "float64",
Description: "current air pressure",
},
{
Name: "main_sealevel",
Type: "float64",
Description: "current sealevel",
},
{
Name: "main_grndlevel",
Type: "float64",
Description: "current groundlevel",
},
{
Name: "main_humidity",
Type: "float64",
Description: "main humidity",
},
{
Name: "wind_speed",
Type: "float64",
Description: "wind speed",
},
{
Name: "wind_deg",
Type: "float64",
Description: "wind degree",
},
{
Name: "clouds_all",
Type: "int",
Description: "clouds",
},
{
Name: "rain",
Type: "map[string]float64",
Description: "rain",
},
{
Name: "snow",
Type: "map[string]float64",
Description: "snow",
},
{
Name: "dt",
Type: "int",
Description: "dt",
},
{
Name: "id",
Type: "int",
Description: "id",
},
{
Name: "name",
Type: "string",
Description: "name",
},
{
Name: "cod",
Type: "int",
Description: "cod",
},
{
Name: "unit",
Type: "string",
Description: "unit meassurement system",
},
{
Name: "lang",
Type: "string",
Description: "language",
},
{
Name: "key",
Type: "string",
Description: "key",
},
},
},
{
Namespace: factory.Name(),
Name: "main_weather",
Description: "returns main measurement weather informations",
Options: []bees.PlaceholderDescriptor{
{
Name: "id",
Type: "int",
Description: "weather id",
},
{
Name: "main",
Type: "string",
Description: "main weather information",
},
{
Name: "description",
Type: "string",
Description: "current weather main description",
},
{
Name: "icon",
Type: "string",
Description: "weather icon",
},
},
},
}
return events
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_response.go#L45-L50 | go | train | // Init a new response | func (r *ActionResponse) Init(context smolder.APIContext) | // Init a new response
func (r *ActionResponse) Init(context smolder.APIContext) | {
r.Parent = r
r.Context = context
r.Actions = []actionInfoResponse{}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_response.go#L53-L56 | go | train | // AddAction adds a action to the response | func (r *ActionResponse) AddAction(action *bees.Action) | // AddAction adds a action to the response
func (r *ActionResponse) AddAction(action *bees.Action) | {
r.actions = append(r.actions, action)
r.Actions = append(r.Actions, prepareActionResponse(r.Context, action))
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_response.go#L59-L68 | go | train | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with | func (r *ActionResponse) EmptyResponse() interface{} | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *ActionResponse) EmptyResponse() interface{} | {
if len(r.actions) == 0 {
var out struct {
Actions interface{} `json:"actions"`
}
out.Actions = []actionInfoResponse{}
return out
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/huebee/huebeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/huebee/huebeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *HueBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *HueBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := HueBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/logs/logs_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_response.go#L48-L53 | go | train | // Init a new response | func (r *LogResponse) Init(context smolder.APIContext) | // Init a new response
func (r *LogResponse) Init(context smolder.APIContext) | {
r.Parent = r
r.Context = context
r.Logs = []logInfoResponse{}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/logs/logs_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_response.go#L56-L59 | go | train | // AddLog adds a log to the response | func (r *LogResponse) AddLog(log *bees.LogMessage) | // AddLog adds a log to the response
func (r *LogResponse) AddLog(log *bees.LogMessage) | {
r.logs = append(r.logs, log)
r.Logs = append(r.Logs, prepareLogResponse(r.Context, log))
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/logs/logs_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/logs/logs_response.go#L62-L71 | go | train | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with | func (r *LogResponse) EmptyResponse() interface{} | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *LogResponse) EmptyResponse() interface{} | {
if len(r.logs) == 0 {
var out struct {
Logs interface{} `json:"logs"`
}
out.Logs = []logInfoResponse{}
return out
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/actions.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/actions.go#L51-L59 | go | train | // GetAction returns one action with a specific ID. | func GetAction(id string) *Action | // GetAction returns one action with a specific ID.
func GetAction(id string) *Action | {
for _, a := range actions {
if a.ID == id {
return &a
}
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/actions.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/actions.go#L67-L118 | go | train | // execAction executes an action and map its ins & outs. | func execAction(action Action, opts map[string]interface{}) bool | // execAction executes an action and map its ins & outs.
func execAction(action Action, opts map[string]interface{}) bool | {
a := Action{
Bee: action.Bee,
Name: action.Name,
}
for _, opt := range action.Options {
ph := Placeholder{
Name: opt.Name,
}
switch opt.Value.(type) {
case string:
var value bytes.Buffer
tmpl, err := template.New(action.Bee + "_" + action.Name + "_" + opt.Name).Funcs(templatehelper.FuncMap).Parse(opt.Value.(string))
if err == nil {
err = tmpl.Execute(&value, opts)
}
if err != nil {
panic(err)
}
ph.Type = "string"
ph.Value = value.String()
default:
ph.Type = opt.Type
ph.Value = opt.Value
}
a.Options = append(a.Options, ph)
}
bee := GetBee(a.Bee)
if (*bee).IsRunning() {
(*bee).LogAction()
log.Println("\tExecuting action:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
(*bee).Action(a)
} else {
log.Println("\tNot executing action on stopped bee:", a.Bee, "/", a.Name, "-", GetActionDescriptor(&a).Description)
for _, v := range a.Options {
log.Println("\t\tOptions:", v)
}
}
return true
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/context/context.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/context/context.go#L36-L41 | go | train | // NewAPIContext returns a new polly context | func (context *APIContext) NewAPIContext() smolder.APIContext | // NewAPIContext returns a new polly context
func (context *APIContext) NewAPIContext() smolder.APIContext | {
ctx := &APIContext{
Config: context.Config,
}
return ctx
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/context/context.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/context/context.go#L44-L56 | go | train | // Authentication parses the request for an access-/authtoken and returns the matching user | func (context *APIContext) Authentication(request *restful.Request) (interface{}, error) | // Authentication parses the request for an access-/authtoken and returns the matching user
func (context *APIContext) Authentication(request *restful.Request) (interface{}, error) | {
//FIXME: implement this properly
t := request.QueryParameter("accesstoken")
if len(t) == 0 {
t = request.HeaderParameter("authorization")
if strings.Index(t, " ") > 0 {
t = strings.TrimSpace(strings.Split(t, " ")[1])
}
}
return nil, nil // context.GetUserByAccessToken(t)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/simplepushbee/simplepushbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/simplepushbee/simplepushbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *SimplepushBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *SimplepushBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := SimplepushBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/placeholders.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L45-L61 | go | train | // SetValue sets a value in the Placeholder slice. | func (ph *Placeholders) SetValue(name string, _type string, value interface{}) | // SetValue sets a value in the Placeholder slice.
func (ph *Placeholders) SetValue(name string, _type string, value interface{}) | {
if ph.Value(name) == nil {
p := Placeholder{
Name: name,
Type: _type,
Value: value,
}
*ph = append(*ph, p)
} else {
for i := 0; i < len(*ph); i++ {
if (*ph)[i].Name == name {
(*ph)[i].Type = _type
(*ph)[i].Value = value
}
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/placeholders.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L64-L72 | go | train | // Value retrieves a value from a Placeholder slice. | func (ph Placeholders) Value(name string) interface{} | // Value retrieves a value from a Placeholder slice.
func (ph Placeholders) Value(name string) interface{} | {
for _, p := range ph {
if p.Name == name {
return p.Value
}
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/placeholders.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L75-L82 | go | train | // Bind a value from a Placeholder slice. | func (ph Placeholders) Bind(name string, dst interface{}) error | // Bind a value from a Placeholder slice.
func (ph Placeholders) Bind(name string, dst interface{}) error | {
v := ph.Value(name)
if v == nil {
return errors.New("Placeholder with name " + name + " not found")
}
return ConvertValue(v, dst)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/placeholders.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/placeholders.go#L85-L233 | go | train | // ConvertValue tries to convert v to dst. | func ConvertValue(v interface{}, dst interface{}) error | // ConvertValue tries to convert v to dst.
func ConvertValue(v interface{}, dst interface{}) error | {
switch d := dst.(type) {
case *string:
switch vt := v.(type) {
case string:
*d = vt
case []string:
*d = strings.Join(vt, ",")
case bool:
*d = strconv.FormatBool(vt)
case int64:
*d = strconv.FormatInt(vt, 10)
case float64:
*d = strconv.FormatFloat(vt, 'f', -1, 64)
case int:
*d = strconv.FormatInt(int64(vt), 10)
default:
panic(fmt.Sprintf("Unhandled type %+v for string conversion", reflect.TypeOf(vt)))
}
case *[]string:
switch vt := v.(type) {
case []interface{}:
*d = []string{}
for _, v := range vt {
*d = append(*d, v.(string))
}
case []string:
*d = vt
case string:
*d = strings.Split(vt, ",")
default:
panic(fmt.Sprintf("Unhandled type %+v for []string conversion", reflect.TypeOf(vt)))
}
case *bool:
switch vt := v.(type) {
case bool:
*d = vt
case string:
vt = strings.ToLower(vt)
if vt == "true" || vt == "on" || vt == "yes" || vt == "1" || vt == "t" {
*d = true
}
case int64:
*d = vt > 0
case int:
*d = vt > 0
case uint64:
*d = vt > 0
case uint:
*d = vt > 0
case float64:
*d = vt > 0
default:
panic(fmt.Sprintf("Unhandled type %+v for bool conversion", reflect.TypeOf(vt)))
}
case *float64:
switch vt := v.(type) {
case int64:
*d = float64(vt)
case int32:
*d = float64(vt)
case int16:
*d = float64(vt)
case int8:
*d = float64(vt)
case int:
*d = float64(vt)
case uint64:
*d = float64(vt)
case uint32:
*d = float64(vt)
case uint16:
*d = float64(vt)
case uint8:
*d = float64(vt)
case uint:
*d = float64(vt)
case float64:
*d = vt
case float32:
*d = float64(vt)
case string:
x, _ := strconv.ParseFloat(vt, 64)
*d = float64(x)
default:
panic(fmt.Sprintf("Unhandled type %+v for float64 conversion", reflect.TypeOf(vt)))
}
case *int:
switch vt := v.(type) {
case int64:
*d = int(vt)
case int32:
*d = int(vt)
case int16:
*d = int(vt)
case int8:
*d = int(vt)
case int:
*d = vt
case uint64:
*d = int(vt)
case uint32:
*d = int(vt)
case uint16:
*d = int(vt)
case uint8:
*d = int(vt)
case uint:
*d = int(vt)
case float64:
*d = int(vt)
case float32:
*d = int(vt)
case string:
*d, _ = strconv.Atoi(vt)
default:
panic(fmt.Sprintf("Unhandled type %+v for int conversion", reflect.TypeOf(vt)))
}
case *time.Time:
switch vt := v.(type) {
case time.Time:
*d = vt
case int:
*d = time.Unix(int64(vt), 0)
case int64:
*d = time.Unix(vt, 0)
default:
panic(fmt.Sprintf("Unhandled type %+v for time.Time conversion", reflect.TypeOf(vt)))
}
case *url.Values:
switch vt := v.(type) {
case string:
*d, _ = url.ParseQuery(vt)
default:
panic(fmt.Sprintf("Unhandled type %+v for url.Values conversion", reflect.TypeOf(vt)))
}
default:
panic(fmt.Sprintf("Unhandled dst type %+v", reflect.TypeOf(dst)))
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/alertoverbee/alertoverbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/alertoverbee/alertoverbee.go#L41-L84 | go | train | // Action triggers the action passed to it. | func (mod *AlertOverBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *AlertOverBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
var receiver, title, content, weburl, priority string
action.Options.Bind("receiver", &receiver)
action.Options.Bind("title", &title)
action.Options.Bind("content", &content)
action.Options.Bind("url", &weburl)
action.Options.Bind("priority", &priority)
if priority == "" {
priority = "0"
}
// the message must be plain text, so
// remove the HTML tags, such as <html></html> and so on
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
content = re.ReplaceAllString(content, "\n")
data := url.Values{
"source": {mod.source},
"receiver": {receiver},
"title": {title},
"content": {content},
"url": {weburl},
"priority": {priority},
}
resp, err := http.PostForm("https://api.alertover.com/v1/alert", data)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
mod.Logln("AlertOver send message success.")
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/alertoverbee/alertoverbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/alertoverbee/alertoverbee.go#L87-L90 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *AlertOverBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *AlertOverBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("source", &mod.source)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/descriptors.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/descriptors.go#L65-L78 | go | train | // GetActionDescriptor returns the ActionDescriptor matching an action. | func GetActionDescriptor(action *Action) ActionDescriptor | // GetActionDescriptor returns the ActionDescriptor matching an action.
func GetActionDescriptor(action *Action) ActionDescriptor | {
bee := GetBee(action.Bee)
if bee == nil {
panic("Bee " + action.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ac := range factory.Actions() {
if ac.Name == action.Name {
return ac
}
}
return ActionDescriptor{}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/descriptors.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/descriptors.go#L81-L94 | go | train | // GetEventDescriptor returns the EventDescriptor matching an event. | func GetEventDescriptor(event *Event) EventDescriptor | // GetEventDescriptor returns the EventDescriptor matching an event.
func GetEventDescriptor(event *Event) EventDescriptor | {
bee := GetBee(event.Bee)
if bee == nil {
panic("Bee " + event.Bee + " not registered")
}
factory := (*GetFactory((*bee).Namespace()))
for _, ev := range factory.Events() {
if ev.Name == event.Name {
return ev
}
}
return EventDescriptor{}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/serialbee/serialbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/serialbee/serialbee.go#L45-L69 | go | train | // Action triggers the action passed to it. | func (mod *SerialBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *SerialBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
text := ""
switch action.Name {
case "send":
action.Options.Bind("text", &text)
bufOut := new(bytes.Buffer)
err := binary.Write(bufOut, binary.LittleEndian, []byte(text))
if err != nil {
panic(err)
}
_, err = mod.conn.Write(bufOut.Bytes())
if err != nil {
panic(err)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/serialbee/serialbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/serialbee/serialbee.go#L110-L139 | go | train | // Run executes the Bee's event loop. | func (mod *SerialBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *SerialBee) Run(eventChan chan bees.Event) | {
if mod.baudrate == 0 || mod.device == "" {
return
}
var err error
options := serial.OpenOptions{
PortName: mod.device,
BaudRate: uint(mod.baudrate),
}
mod.conn, err = serial.Open(options)
if err != nil {
mod.LogFatal(err)
}
defer mod.conn.Close()
go func() {
for {
if err := mod.handleEvents(eventChan); err != nil {
return
}
}
}()
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/serialbee/serialbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/serialbee/serialbee.go#L142-L147 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *SerialBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *SerialBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("device", &mod.device)
options.Bind("baudrate", &mod.baudrate)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mastodonbee/mastodonbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mastodonbee/mastodonbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *mastodonBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *mastodonBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := mastodonBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mastodonbee/mastodonbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mastodonbee/mastodonbeefactory.go#L68-L102 | go | train | // Options returns the options available to configure this Bee. | func (factory *mastodonBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *mastodonBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "server",
Description: "URL for the desired mastodon server",
Type: "string",
Mandatory: true,
},
{
Name: "client_id",
Description: "Client id for the mastodon client",
Type: "string",
Mandatory: true,
},
{
Name: "client_secret",
Description: "Client secret for the mastodon client",
Type: "string",
Mandatory: true,
},
{
Name: "email",
Description: "User account email",
Type: "string",
Mandatory: true,
},
{
Name: "password",
Description: "User account password",
Type: "string",
Mandatory: true,
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cricketbee/cricketbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cricketbee/cricketbee.go#L101-L104 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *CricketBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *CricketBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("favourite_team", &mod.favTeam)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/twitterbee/twitterbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/twitterbee/twitterbeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *TwitterBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *TwitterBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := TwitterBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/twitterbee/twitterbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/twitterbee/twitterbeefactory.go#L69-L93 | go | train | // Options returns the options available to configure this Bee. | func (factory *TwitterBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *TwitterBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "consumer_key",
Description: "Consumer key for Twitter API",
Type: "string",
},
{
Name: "consumer_secret",
Description: "Consumer secret for Twitter API",
Type: "string",
},
{
Name: "access_token",
Description: "Access token for Twitter API",
Type: "string",
},
{
Name: "access_token_secret",
Description: "API secret for Twitter API",
Type: "string",
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *IrcBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *IrcBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := IrcBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbeefactory.go#L68-L102 | go | train | // Options returns the options available to configure this Bee. | func (factory *IrcBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *IrcBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "address",
Description: "Hostname of IRC server, eg: irc.example.org:6667",
Type: "address",
Mandatory: true,
},
{
Name: "nick",
Description: "Nickname to use for IRC",
Type: "string",
Default: "beehive",
Mandatory: true,
},
{
Name: "password",
Description: "Password to use to connect to IRC server",
Type: "password",
},
{
Name: "channels",
Description: "Which channels to join",
Type: "[]string",
Mandatory: true,
},
{
Name: "ssl",
Description: "Use SSL for IRC connection",
Default: false,
Type: "bool",
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/ircbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/ircbeefactory.go#L105-L119 | go | train | // States returns the state values provided by this Bee. | func (factory *IrcBeeFactory) States() []bees.StateDescriptor | // States returns the state values provided by this Bee.
func (factory *IrcBeeFactory) States() []bees.StateDescriptor | {
opts := []bees.StateDescriptor{
{
Name: "connected",
Description: "Whether this bee is currently connected to IRC",
Type: "bool",
},
{
Name: "channels",
Description: "Which channels this bee is currently connected to",
Type: "[]string",
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_get.go#L54-L69 | go | train | // GetByIDs sends out all items matching a set of IDs | func (r *BeeResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) | // GetByIDs sends out all items matching a set of IDs
func (r *BeeResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) | {
resp := BeeResponse{}
resp.Init(ctx)
for _, id := range ids {
bee := bees.GetBee(id)
if bee == nil {
r.NotFound(request, response)
return
}
resp.AddBee(bee)
}
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_get.go#L72-L83 | go | train | // Get sends out items matching the query parameters | func (r *BeeResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | // Get sends out items matching the query parameters
func (r *BeeResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | {
// ctxapi := ctx.(*context.APIContext)
bees := bees.GetBees()
resp := BeeResponse{}
resp.Init(ctx)
for _, bee := range bees {
resp.AddBee(bee)
}
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_response.go#L50-L55 | go | train | // Init a new response | func (r *ChainResponse) Init(context smolder.APIContext) | // Init a new response
func (r *ChainResponse) Init(context smolder.APIContext) | {
r.Parent = r
r.Context = context
r.chains = make(map[string]*bees.Chain)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_response.go#L58-L60 | go | train | // AddChain adds a chain to the response | func (r *ChainResponse) AddChain(chain bees.Chain) | // AddChain adds a chain to the response
func (r *ChainResponse) AddChain(chain bees.Chain) | {
r.chains[chain.Name] = &chain
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_response.go#L63-L75 | go | train | // Send responds to a request with http.StatusOK | func (r *ChainResponse) Send(response *restful.Response) | // Send responds to a request with http.StatusOK
func (r *ChainResponse) Send(response *restful.Response) | {
var keys []string
for k := range r.chains {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
r.Chains = append(r.Chains, prepareChainResponse(r.Context, r.chains[k]))
}
r.Response.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_response.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_response.go#L78-L87 | go | train | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with | func (r *ChainResponse) EmptyResponse() interface{} | // EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *ChainResponse) EmptyResponse() interface{} | {
if len(r.chains) == 0 {
var out struct {
Chains interface{} `json:"chains"`
}
out.Chains = []chainInfoResponse{}
return out
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/notificationbee/notificationbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/notificationbee/notificationbee.go#L65-L87 | go | train | // Action triggers the action passed to it. | func (mod *NotificationBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *NotificationBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "notify":
text := ""
u := ""
urgency := UrgencyNormal
action.Options.Bind("text", &text)
action.Options.Bind("urgency", &u)
text = strings.TrimSpace(text)
urgency, _ = urgencyMap[u]
if len(text) > 0 {
mod.execAction(text, urgency)
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/cronparser.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L41-L110 | go | train | // ParseInput parses the input and returns a pointer to the generated datastructure.
// input[0]: Second
// input[1]: Minute
// input[2]: Hour
// input[3]: Weekday
// input[4]: Day (of Month)
// input[5]: Month | func ParseInput(input [6]string) *crontime | // ParseInput parses the input and returns a pointer to the generated datastructure.
// input[0]: Second
// input[1]: Minute
// input[2]: Hour
// input[3]: Weekday
// input[4]: Day (of Month)
// input[5]: Month
func ParseInput(input [6]string) *crontime | {
var result crontime
// Check the syntax of the input
for i := 0; i != len(input); i++ {
if checkSyntax(input[i]) == false {
log.Panicln("Invalid config at Line", i) // TODO be more helpful
}
}
// Parse Input like 23-05
for i := 0; i != len(input); i++ {
if strings.Contains(input[i], "-") {
result.parseRange(input[i], i)
}
}
// Parse Input like 05,23,17
for i := 0; i != len(input); i++ {
if strings.Contains(input[i], ",") {
result.parseIRange(input[i], i)
}
}
// Parse input like */05
for i := 0; i != len(input); i++ {
if strings.Contains(input[i], "*/") {
result.parsePeriodic(input[i], i)
}
}
// Parse input like *
for i := 0; i != len(input); i++ {
if input[i] == "*" {
result.parseIgnore(i)
}
}
//Parse single Numbers (05 or 23)
for i := 0; i != len(input); i++ {
if !strings.ContainsAny(input[i], "-*/,") {
tempary := make([]int, 1)
temp, err := strconv.ParseInt(input[i], 10, 0)
tempary[0] = int(temp)
if err != nil {
panic(err)
}
switch i {
case 0:
result.second = tempary
case 1:
result.minute = tempary
case 2:
result.hour = tempary
case 3:
result.dow = tempary
case 4:
result.dom = tempary
case 5:
result.month = tempary
}
}
}
// Do a sanity check, eg. there is no 32th Day in any Month
result.checkValues()
// Makes timestamp generation easier
sort.Ints(result.second)
sort.Ints(result.minute)
sort.Ints(result.hour)
sort.Ints(result.dow)
sort.Ints(result.dom)
sort.Ints(result.month)
return &result
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/cronparser.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L285-L321 | go | train | // Look for obvious nonsense in the config. | func (c *crontime) checkValues() | // Look for obvious nonsense in the config.
func (c *crontime) checkValues() | {
for _, sec := range c.second {
if sec >= 60 || sec < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Second\".")
}
}
for _, min := range c.second {
if min >= 60 || min < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Minute\".")
}
}
for _, hour := range c.hour {
if hour >= 24 || hour < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Hour\".")
}
}
for _, dow := range c.dow {
if dow >= 7 || dow < 0 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfWeek\".")
}
}
for _, dom := range c.dom {
if dom >= 32 || dom < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"DayOfMonth\".")
}
}
for _, month := range c.month {
if month >= 13 || month < 1 {
log.Panicln("Cronbee: Your config seems messed up. Check the range of \"Month\".")
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/cronparser.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L331-L342 | go | train | // 'Absolute' value (or distance) with an variable base.
// Example: absoluteOverBreakpoint(59, 1, 60) returns 2 | func absoluteOverBreakpoint(a, b, base int) int | // 'Absolute' value (or distance) with an variable base.
// Example: absoluteOverBreakpoint(59, 1, 60) returns 2
func absoluteOverBreakpoint(a, b, base int) int | {
if a >= base || b >= base {
panic("Invalid Values")
}
if a < b {
return b - a
} else if a == b {
return 0
} else {
return (base - a) + b
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cronbee/cron/cronparser.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cronbee/cron/cronparser.go#L346-L358 | go | train | // Returns an array filled with all values between a and b considering
// the base. | func valueRange(a, b, base int) []int | // Returns an array filled with all values between a and b considering
// the base.
func valueRange(a, b, base int) []int | {
value := make([]int, absoluteOverBreakpoint(a, b, base)+1)
i := 0
for ; a != b; a++ {
if a == base {
a = 0
}
value[i] = a
i++
}
value[i] = a
return value
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/hellobee/hellobee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/hellobee/hellobee.go#L49-L51 | go | train | // Action triggers the action passed to it. | func (mod *HelloBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *HelloBee) Action(action bees.Action) []bees.Placeholder | {
return []bees.Placeholder{}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/transmissionbee/transmissionbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/transmissionbee/transmissionbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *TransmissionBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *TransmissionBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := TransmissionBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/transmissionbee/transmissionbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/transmissionbee/transmissionbeefactory.go#L68-L90 | go | train | // Options returns the options available to configure this Bee. | func (factory *TransmissionBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *TransmissionBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "url",
Description: "Server URL",
Type: "url",
Mandatory: true,
Default: "http://localhost:9091/transmission/rpc",
},
{
Name: "username",
Description: "Username",
Type: "string",
Mandatory: true,
},
{
Name: "password",
Description: "Password",
Type: "password",
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/anelpowerctrlbee/anelpowerctrlbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/anelpowerctrlbee/anelpowerctrlbee.go#L70-L87 | go | train | // Action triggers the action passed to it. | func (mod *AnelPowerCtrlBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *AnelPowerCtrlBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "switch":
socket := 0
state := false
action.Options.Bind("socket", &socket)
action.Options.Bind("state", &state)
mod.anelSwitch(socket, state)
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/anelpowerctrlbee/anelpowerctrlbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/anelpowerctrlbee/anelpowerctrlbee.go#L90-L96 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *AnelPowerCtrlBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *AnelPowerCtrlBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.addr)
options.Bind("user", &mod.user)
options.Bind("password", &mod.password)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/webbee/webbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/webbee/webbee.go#L46-L69 | go | train | // Run executes the Bee's event loop. | func (mod *WebBee) Run(cin chan bees.Event) | // Run executes the Bee's event loop.
func (mod *WebBee) Run(cin chan bees.Event) | {
mod.eventChan = cin
srv := &http.Server{Addr: mod.addr, Handler: mod}
l, err := net.Listen("tcp", mod.addr)
if err != nil {
mod.LogErrorf("Can't listen on %s", mod.addr)
return
}
defer l.Close()
go func() {
err := srv.Serve(l)
if err != nil {
mod.LogErrorf("Server error: %v", err)
}
// Go 1.8+: srv.Close()
}()
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/webbee/webbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/webbee/webbee.go#L123-L127 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *WebBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *WebBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.addr)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_post.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_post.go#L58-L84 | go | train | // Post processes an incoming POST (create) request | func (r *ChainResource) Post(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | // Post processes an incoming POST (create) request
func (r *ChainResource) Post(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | {
resp := ChainResponse{}
resp.Init(context)
pps := data.(*ChainPostStruct)
dupe := bees.GetChain(pps.Chain.Name)
if dupe != nil {
smolder.ErrorResponseHandler(request, response, nil, smolder.NewErrorResponse(
422, // Go 1.7+: http.StatusUnprocessableEntity,
errors.New("A Chain with that name exists already"),
"ChainResource POST"))
return
}
chain := bees.Chain{
Name: pps.Chain.Name,
Description: pps.Chain.Description,
Event: &pps.Chain.Event,
Actions: pps.Chain.Actions,
Filters: pps.Chain.Filters,
}
chains := append(bees.GetChains(), chain)
bees.SetChains(chains)
resp.AddChain(chain)
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/httpbee/httpbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/httpbee/httpbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *HTTPBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *HTTPBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := HTTPBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/rssbee/rssbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/rssbee/rssbee.go#L157-L162 | go | train | // Run executes the Bee's event loop. | func (mod *RSSBee) Run(cin chan bees.Event) | // Run executes the Bee's event loop.
func (mod *RSSBee) Run(cin chan bees.Event) | {
mod.eventChan = cin
time.Sleep(10 * time.Second)
mod.pollFeed(mod.url, 5)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/rssbee/rssbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/rssbee/rssbee.go#L165-L170 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *RSSBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *RSSBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("skip_first", &mod.skipNextFetch)
options.Bind("url", &mod.url)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/webbee/webbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/webbee/webbeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *WebBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *WebBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := WebBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/webbee/webbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/webbee/webbeefactory.go#L68-L78 | go | train | // Options returns the options available to configure this Bee. | func (factory *WebBeeFactory) Options() []bees.BeeOptionDescriptor | // Options returns the options available to configure this Bee.
func (factory *WebBeeFactory) Options() []bees.BeeOptionDescriptor | {
opts := []bees.BeeOptionDescriptor{
{
Name: "address",
Description: "Which addr to listen on, eg: 0.0.0.0:12345",
Type: "address",
Mandatory: true,
},
}
return opts
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/bees/bees_put.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/bees/bees_put.go#L45-L68 | go | train | // Put processes an incoming PUT (update) request | func (r *BeeResource) Put(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | // Put processes an incoming PUT (update) request
func (r *BeeResource) Put(context smolder.APIContext, data interface{}, request *restful.Request, response *restful.Response) | {
resp := BeeResponse{}
resp.Init(context)
pps := data.(*BeePostStruct)
id := request.PathParameter("bee-id")
bee := bees.GetBee(id)
if bee == nil {
r.NotFound(request, response)
return
}
(*bee).SetDescription(pps.Bee.Description)
(*bee).ReloadOptions(pps.Bee.Options)
if pps.Bee.Active {
bees.RestartBee(bee)
} else {
(*bee).Stop()
}
resp.AddBee(bee)
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_get.go#L54-L69 | go | train | // GetByIDs sends out all items matching a set of IDs | func (r *ActionResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) | // GetByIDs sends out all items matching a set of IDs
func (r *ActionResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) | {
resp := ActionResponse{}
resp.Init(ctx)
for _, id := range ids {
action := bees.GetAction(id)
if action == nil {
r.NotFound(request, response)
return
}
resp.AddAction(action)
}
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/actions/actions_get.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/actions/actions_get.go#L72-L88 | go | train | // Get sends out items matching the query parameters | func (r *ActionResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | // Get sends out items matching the query parameters
func (r *ActionResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) | {
// ctxapi := ctx.(*context.APIContext)
actions := bees.GetActions()
if len(actions) == 0 {
r.NotFound(request, response)
return
}
resp := ActionResponse{}
resp.Init(ctx)
for _, action := range actions {
resp.AddAction(&action)
}
resp.Send(response)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/logs.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L52-L60 | go | train | // NewLogMessage returns a newly composed LogMessage | func NewLogMessage(bee string, message string, messageType uint) LogMessage | // NewLogMessage returns a newly composed LogMessage
func NewLogMessage(bee string, message string, messageType uint) LogMessage | {
return LogMessage{
ID: UUID(),
Bee: bee,
Message: message,
MessageType: messageType,
Timestamp: time.Now(),
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/logs.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L63-L68 | go | train | // Log adds a new LogMessage to the log | func Log(bee string, message string, messageType uint) | // Log adds a new LogMessage to the log
func Log(bee string, message string, messageType uint) | {
logMutex.Lock()
defer logMutex.Unlock()
logs[bee] = append(logs[bee], NewLogMessage(bee, message, messageType))
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/logs.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/logs.go#L71-L86 | go | train | // GetLogs returns all logs for a Bee. | func GetLogs(bee string) []LogMessage | // GetLogs returns all logs for a Bee.
func GetLogs(bee string) []LogMessage | {
r := []LogMessage{}
logMutex.RLock()
for b, ls := range logs {
if len(bee) == 0 || bee == b {
for _, l := range ls {
r = append(r, l)
}
}
}
logMutex.RUnlock()
sort.Sort(LogSorter(r))
return r
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/s3bee/s3bee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/s3bee/s3bee.go#L39-L66 | go | train | // Action triggers the action passed to it. | func (bee *S3Bee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (bee *S3Bee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "upload":
bucket := ""
action.Options.Bind("bucket", &bucket)
path := ""
action.Options.Bind("path", &path)
objectPath := ""
action.Options.Bind("object_path", &objectPath)
if objectPath == "" {
objectPath = filepath.Base(path)
}
_, err := bee.client.FPutObject(bucket, objectPath, path, minio.PutObjectOptions{ContentType: mime.TypeByExtension(filepath.Ext(path))})
if err != nil {
bee.LogFatal(err)
}
default:
panic("Unknown action triggered in " + bee.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/ircbee/irctools/irctools.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/ircbee/irctools/irctools.go#L38-L80 | go | train | // Colored wraps val in color styling tags. | func Colored(val string, color string) string | // Colored wraps val in color styling tags.
func Colored(val string, color string) string | {
// 00 white 01 black 02 blue (navy) 03 green 04 red 05 brown (maroon)
// 06 purple 07 orange (olive) 08 yellow 09 light green (lime)
// 10 teal (a green/blue cyan) 11 light cyan (cyan) (aqua) 12 light blue (royal)
// 13 pink (light purple) (fuchsia) 14 grey 15 light grey (silver)
c := "01"
switch color {
case "white":
c = "00"
case "black":
c = "01"
case "blue":
c = "02"
case "green":
c = "03"
case "red":
c = "04"
case "brown":
c = "05"
case "purple":
c = "06"
case "orange":
c = "07"
case "yellow":
c = "08"
case "lime":
c = "09"
case "teal":
c = "10"
case "cyan":
c = "11"
case "lightblue":
c = "12"
case "pink":
c = "13"
case "grey":
c = "14"
case "silver":
c = "15"
}
return "\x03" + c + val + "\x03"
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cleverbotbee/cleverbotbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cleverbotbee/cleverbotbee.go#L44-L76 | go | train | // Action triggers the action passed to it. | func (mod *CleverbotBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *CleverbotBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send_message":
var text string
action.Options.Bind("text", &text)
resp, err := mod.client.Ask(text)
if err != nil {
mod.LogErrorf("Failed to ask cleverbot: %v", err)
return nil
}
ev := bees.Event{
Bee: mod.Name(),
Name: "answer",
Options: []bees.Placeholder{
{
Name: "answer",
Type: "string",
Value: resp,
},
},
}
mod.evchan <- ev
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cleverbotbee/cleverbotbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cleverbotbee/cleverbotbee.go#L79-L93 | go | train | // Run executes the Bee's event loop. | func (mod *CleverbotBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *CleverbotBee) Run(eventChan chan bees.Event) | {
mod.evchan = eventChan
client, err := cleverbot.New(mod.api_user, mod.api_key, mod.session_nick)
if err != nil {
mod.LogErrorf("Failed to start session: %v", err)
return
}
mod.client = client
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/cleverbotbee/cleverbotbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/cleverbotbee/cleverbotbee.go#L96-L102 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *CleverbotBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *CleverbotBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("api_user", &mod.api_user)
options.Bind("api_key", &mod.api_key)
options.Bind("session_nick", &mod.session_nick)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/notificationbee/notificationbee_osx.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/notificationbee/notificationbee_osx.go#L29-L33 | 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) | {
note := gosxnotifier.NewNotification("Beehive")
note.Title = text
note.Push()
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/nagiosbee/nagiosbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/nagiosbee/nagiosbeefactory.go#L35-L43 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *NagiosBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *NagiosBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := NagiosBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.services = make(map[string]map[string]service)
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | api/resources/chains/chains_delete.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/api/resources/chains/chains_delete.go#L45-L67 | go | train | // Delete processes an incoming DELETE request | func (r *ChainResource) Delete(context smolder.APIContext, request *restful.Request, response *restful.Response) | // Delete processes an incoming DELETE request
func (r *ChainResource) Delete(context smolder.APIContext, request *restful.Request, response *restful.Response) | {
resp := ChainResponse{}
resp.Init(context)
id := request.PathParameter("chain-id")
found := false
chains := []bees.Chain{}
for _, v := range bees.GetChains() {
if v.Name == id {
found = true
} else {
chains = append(chains, v)
}
}
if found {
bees.SetChains(chains)
resp.Send(response)
} else {
r.NotFound(request, response)
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/transmissionbee/transmissionbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/transmissionbee/transmissionbee.go#L41-L54 | go | train | // Action triggers the action passed to it. | func (mod *TransmissionBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *TransmissionBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "add_torrent":
torrentMsg := ""
action.Options.Bind("torrent", &torrentMsg)
_, err := mod.client.Add(torrentMsg)
if err != nil {
mod.LogErrorf("Error adding torrent/magnet: %s", err)
}
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/transmissionbee/transmissionbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/transmissionbee/transmissionbee.go#L57-L70 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *TransmissionBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *TransmissionBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
conf := transmission.Config{}
options.Bind("url", &conf.Address)
options.Bind("username", &conf.User)
options.Bind("password", &conf.Password)
t, err := transmission.New(conf)
if err != nil {
pretty.Println(err)
}
mod.client = t
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/options.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/options.go#L46-L54 | go | train | // Value retrieves a value from a BeeOptions slice. | func (opts BeeOptions) Value(name string) interface{} | // Value retrieves a value from a BeeOptions slice.
func (opts BeeOptions) Value(name string) interface{} | {
for _, opt := range opts {
if opt.Name == name {
return opt.Value
}
}
return nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/options.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/options.go#L57-L64 | go | train | // Bind a value from a BeeOptions slice. | func (opts BeeOptions) Bind(name string, dst interface{}) error | // Bind a value from a BeeOptions slice.
func (opts BeeOptions) Bind(name string, dst interface{}) error | {
v := opts.Value(name)
if v == nil {
return errors.New("Option with name " + name + " not found")
}
return ConvertValue(v, dst)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mumblebee/mumblebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mumblebee/mumblebee.go#L52-L89 | go | train | // Action triggers the action passed to it. | func (mod *MumbleBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *MumbleBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send_to_user":
user, text := "", ""
action.Options.Bind("user", &user)
action.Options.Bind("text", &text)
mod.client.Users.Find(user).Send(text)
case "send_to_channel":
channel, text := "", ""
action.Options.Bind("channel", &channel)
action.Options.Bind("text", &text)
if channel != "" {
mod.client.Channels.Find(channel).Send(text, false)
} else {
mod.client.Self.Channel.Send(text, false)
}
case "move":
channel := ""
action.Options.Bind("channel", &channel)
mod.move(channel)
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mumblebee/mumblebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mumblebee/mumblebee.go#L109-L317 | go | train | // Run executes the Bee's event loop. | func (mod *MumbleBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *MumbleBee) Run(eventChan chan bees.Event) | {
if len(mod.server) == 0 {
return
}
// channel signaling mumble connection status
mod.connectedState = make(chan bool)
host, port, err := net.SplitHostPort(mod.server)
if err != nil {
host = mod.server
port = strconv.Itoa(gumble.DefaultPort)
}
config := gumble.NewConfig()
config.Username = mod.user
config.Password = mod.password
address := net.JoinHostPort(host, port)
var tlsConfig tls.Config
if mod.insecure {
tlsConfig.InsecureSkipVerify = true
}
config.Attach(gumbleutil.Listener{
TextMessage: func(e *gumble.TextMessageEvent) {
ev := bees.Event{
Bee: mod.Name(),
Name: "message",
Options: []bees.Placeholder{
{
Name: "channels",
Type: "[]string",
Value: e.Channels,
},
{
Name: "user",
Type: "string",
Value: e.Sender.Name,
},
{
Name: "text",
Type: "string",
Value: e.Message,
},
},
}
eventChan <- ev
},
})
config.Attach(gumbleutil.Listener{
Disconnect: func(e *gumble.DisconnectEvent) {
go func() {
mod.connectedState <- false
}()
},
})
config.Attach(gumbleutil.Listener{
Connect: func(e *gumble.ConnectEvent) {
go func() {
mod.connectedState <- true
}()
},
})
config.Attach(gumbleutil.Listener{
UserChange: func(e *gumble.UserChangeEvent) {
eventType := ""
if e.Type.Has(gumble.UserChangeConnected) {
eventType = "user_connected"
} else if e.Type.Has(gumble.UserChangeDisconnected) {
eventType = "user_disconnected"
} else if e.Type.Has(gumble.UserChangeRegistered) {
eventType = "user_registered"
} else {
return
}
ev := bees.Event{
Bee: mod.Name(),
Name: eventType,
Options: []bees.Placeholder{
{
Name: "user",
Type: "string",
Value: e.User.Name,
},
},
}
eventChan <- ev
},
})
config.Attach(gumbleutil.Listener{
UserChange: func(e *gumble.UserChangeEvent) {
eventType := ""
if e.Type.Has(gumble.UserChangeKicked) {
eventType = "user_banned"
} else if e.Type.Has(gumble.UserChangeBanned) {
eventType = "user_kicked"
} else {
return
}
ev := bees.Event{
Bee: mod.Name(),
Name: eventType,
Options: []bees.Placeholder{
{
Name: "user",
Type: "string",
Value: e.User.Name,
},
{
Name: "admin",
Type: "string",
Value: e.Actor.Name,
},
{
Name: "message",
Type: "string",
Value: e.String,
},
},
}
eventChan <- ev
},
})
config.Attach(gumbleutil.Listener{
UserChange: func(e *gumble.UserChangeEvent) {
if e.Type.Has(gumble.UserChangeChannel) {
ev := bees.Event{
Bee: mod.Name(),
Name: "user_changed_channel",
Options: []bees.Placeholder{
{
Name: "user",
Type: "string",
Value: e.User.Name,
},
{
Name: "channel",
Type: "string",
Value: strings.Join(gumbleutil.ChannelPath(e.User.Channel), "/"),
},
},
}
eventChan <- ev
}
},
})
/*/ ToDo: Use own client certs
if *certificateFile != "" {
if *keyFile == "" {
keyFile = certificateFile
}
if certificate, err := tls.LoadX509KeyPair(*certificateFile, *keyFile); err != nil {
fmt.Printf("%s: %s\n", os.Args[0], err)
os.Exit(1)
} else {
tlsConfig.Certificates = append(tlsConfig.Certificates, certificate)
}
}
//*/
config.Attach(gumbleutil.AutoBitrate)
connecting := false
disconnected := true
waitForDisconnect := false
for {
// loop on mumble connection events
if disconnected {
if waitForDisconnect {
return
}
if !connecting {
connecting = true
mod.Logln("Connecting to Mumble:", mod.server)
mod.client, err = gumble.DialWithDialer(new(net.Dialer), address, config, &tlsConfig)
mod.Logln("Connected to:", mod.server)
if err != nil {
mod.Logln("Failed to connect to Mumble:", mod.server, err)
connecting = false
}
}
}
select {
case status := <-mod.connectedState:
if status {
mod.Logln("Connected to Mumble:", mod.server)
connecting = false
disconnected = false
mod.move(mod.channel)
} else {
mod.Logln("Disconnected from Mumble:", mod.server)
connecting = false
disconnected = true
}
case <-mod.SigChan:
if !waitForDisconnect {
mod.client.Disconnect()
}
waitForDisconnect = true
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/mumblebee/mumblebee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/mumblebee/mumblebee.go#L320-L328 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *MumbleBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *MumbleBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
options.Bind("address", &mod.server)
options.Bind("channel", &mod.channel)
options.Bind("user", &mod.user)
options.Bind("password", &mod.password)
options.Bind("insecure", &mod.insecure)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/pushoverbee/pushoverbeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/pushoverbee/pushoverbeefactory.go#L34-L41 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *PushoverBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *PushoverBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := PushoverBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/hellobee/hellobeefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/hellobee/hellobeefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *HelloBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *HelloBeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := HelloBee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/httpbee/httpbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/httpbee/httpbee.go#L45-L52 | go | train | // Run executes the Bee's event loop. | func (mod *HTTPBee) Run(cin chan bees.Event) | // Run executes the Bee's event loop.
func (mod *HTTPBee) Run(cin chan bees.Event) | {
mod.eventChan = cin
select {
case <-mod.SigChan:
return
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/httpbee/httpbee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/httpbee/httpbee.go#L55-L123 | go | train | // Action triggers the action passed to it. | func (mod *HTTPBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *HTTPBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
u := ""
action.Options.Bind("url", &u)
switch action.Name {
case "get":
resp, err := http.Get(u)
if err != nil {
mod.LogErrorf("Error: %s", err)
return outs
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
mod.LogErrorf("Error: %s", err)
return outs
}
ev, err := mod.prepareResponseEvent(b)
if err == nil {
ev.Name = "get"
ev.Options.SetValue("url", "url", u)
mod.eventChan <- ev
}
case "post":
var err error
var b []byte
var j string
var form url.Values
var resp *http.Response
action.Options.Bind("json", &j)
action.Options.Bind("form", &form)
if j != "" {
buf := strings.NewReader(j)
resp, err = http.Post(u, "application/json", buf)
} else {
resp, err = http.PostForm(u, form)
}
if err != nil {
mod.LogErrorf("Error: %s", err)
return outs
}
defer resp.Body.Close()
b, err = ioutil.ReadAll(resp.Body)
if err != nil {
mod.LogErrorf("Error: %s", err)
return outs
}
ev, err := mod.prepareResponseEvent(b)
if err == nil {
ev.Name = "post"
ev.Options.SetValue("url", "url", u)
mod.eventChan <- ev
}
default:
panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/telegrambee/telegrambee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambee.go#L48-L71 | go | train | // Action triggers the action passed to it. | func (mod *TelegramBee) Action(action bees.Action) []bees.Placeholder | // Action triggers the action passed to it.
func (mod *TelegramBee) Action(action bees.Action) []bees.Placeholder | {
outs := []bees.Placeholder{}
switch action.Name {
case "send":
chatID := ""
text := ""
action.Options.Bind("chat_id", &chatID)
action.Options.Bind("text", &text)
cid, err := strconv.ParseInt(chatID, 10, 64)
if err != nil {
panic("Invalid telegram chat ID")
}
msg := telegram.NewMessage(cid, text)
_, err = mod.bot.Send(msg)
if err != nil {
mod.Logf("Error sending message %v", err)
}
}
return outs
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/telegrambee/telegrambee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambee.go#L74-L124 | go | train | // Run executes the Bee's event loop. | func (mod *TelegramBee) Run(eventChan chan bees.Event) | // Run executes the Bee's event loop.
func (mod *TelegramBee) Run(eventChan chan bees.Event) | {
var err error
mod.bot, err = telegram.NewBotAPI(mod.apiKey)
if err != nil {
mod.LogErrorf("Authorization failed, make sure the Telegram API key is correct: %s", err)
return
}
mod.Logf("Authorized on account %s", mod.bot.Self.UserName)
u := telegram.NewUpdate(0)
u.Timeout = 60
updates, err := mod.bot.GetUpdatesChan(u)
if err != nil {
panic(err)
}
for {
select {
case <-mod.SigChan:
return
case update := <-updates:
if update.Message == nil || update.Message.Text == "" {
continue
}
ev := bees.Event{
Bee: mod.Name(),
Name: "message",
Options: []bees.Placeholder{
{
Name: "text",
Type: "string",
Value: update.Message.Text,
},
{
Name: "chat_id",
Type: "string",
Value: strconv.FormatInt(update.Message.Chat.ID, 10),
},
{
Name: "user_id",
Type: "string",
Value: strconv.Itoa(update.Message.From.ID),
},
},
}
eventChan <- ev
}
}
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/telegrambee/telegrambee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambee.go#L127-L132 | go | train | // ReloadOptions parses the config options and initializes the Bee. | func (mod *TelegramBee) ReloadOptions(options bees.BeeOptions) | // ReloadOptions parses the config options and initializes the Bee.
func (mod *TelegramBee) ReloadOptions(options bees.BeeOptions) | {
mod.SetOptions(options)
apiKey := getAPIKey(&options)
mod.apiKey = apiKey
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/telegrambee/telegrambee.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/telegrambee/telegrambee.go#L136-L154 | go | train | // Gets the Bot's API key from a file, the recipe config or the
// TELEGRAM_API_KEY environment variable. | func getAPIKey(options *bees.BeeOptions) string | // Gets the Bot's API key from a file, the recipe config or the
// TELEGRAM_API_KEY environment variable.
func getAPIKey(options *bees.BeeOptions) string | {
var apiKey string
options.Bind("api_key", &apiKey)
if strings.HasPrefix(apiKey, "file://") {
buf, err := ioutil.ReadFile(strings.TrimPrefix(apiKey, "file://"))
if err != nil {
panic("Error reading API key file " + apiKey)
}
apiKey = string(buf)
}
if strings.HasPrefix(apiKey, "env://") {
buf := strings.TrimPrefix(apiKey, "env://")
apiKey = os.Getenv(string(buf))
}
return strings.TrimSpace(apiKey)
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/s3bee/s3beefactory.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/s3bee/s3beefactory.go#L33-L40 | go | train | // New returns a new Bee instance configured with the supplied options. | func (factory *S3BeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | // New returns a new Bee instance configured with the supplied options.
func (factory *S3BeeFactory) New(name, description string, options bees.BeeOptions) bees.BeeInterface | {
bee := S3Bee{
Bee: bees.NewBee(name, factory.ID(), description, options),
}
bee.ReloadOptions(options)
return &bee
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/config.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/config.go#L35-L56 | go | train | // NewBeeConfig validates a configuration and sets up a new BeeConfig | func NewBeeConfig(name, class, description string, options BeeOptions) (BeeConfig, error) | // NewBeeConfig validates a configuration and sets up a new BeeConfig
func NewBeeConfig(name, class, description string, options BeeOptions) (BeeConfig, error) | {
if len(name) == 0 {
return BeeConfig{}, errors.New("A Bee's name can't be empty")
}
b := GetBee(name)
if b != nil {
return BeeConfig{}, errors.New("A Bee with that name already exists")
}
f := GetFactory(class)
if f == nil {
return BeeConfig{}, errors.New("Invalid class specified")
}
return BeeConfig{
Name: name,
Class: class,
Description: description,
Options: options,
}, nil
} |
muesli/beehive | 4bfd4852e0b4bdcbc711323775cc7144ccd81b7e | bees/config.go | https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/bees/config.go#L59-L66 | go | train | // BeeConfigs returns configs for all Bees. | func BeeConfigs() []BeeConfig | // BeeConfigs returns configs for all Bees.
func BeeConfigs() []BeeConfig | {
bs := []BeeConfig{}
for _, b := range bees {
bs = append(bs, (*b).Config())
}
return bs
} |