// Actions takes a list of ActionTags, and returns the full Action for
// each ID.
545273
func (a *ActionAPI) Actions(arg params.Entities) (params.ActionResults, error) {
	if err := a.checkCanRead(); err != nil {
		return params.ActionResults{}, errors.Trace(err)
	}

	response := params.ActionResults{Results: make([]params.ActionResult, len(arg.Entities))}
	for i, entity := range arg.Entities {
		currentResult := &response.Results[i]
		tag, err := names.ParseTag(entity.Tag)
		if err != nil {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		actionTag, ok := tag.(names.ActionTag)
		if !ok {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		m, err := a.state.Model()
		if err != nil {
			return params.ActionResults{}, errors.Trace(err)
		}
		action, err := m.ActionByTag(actionTag)
		if err != nil {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		receiverTag, err := names.ActionReceiverTag(action.Receiver())
		if err != nil {
			currentResult.Error = common.ServerError(err)
			continue
		}
		response.Results[i] = common.MakeActionResult(receiverTag, action)
	}
	return response, nil
}
980125
func (mod *SlackBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		tos := []string{}
		text := ""
		action.Options.Bind("text", &text)

		for _, opt := range action.Options {
			if opt.Name == "channel" {
				cid := mod.findChannelID(opt.Value.(string), false)
				if cid != "" {
					tos = append(tos, cid)
				} else {
					mod.Logf("Error: channel ID for %s not found", opt.Value.(string))
				}
			}
		}

		msgParams := slack.NewPostMessageParameters()
		msgParams.LinkNames = 1
		for _, to := range tos {
			_, _, err := mod.client.PostMessage(to, slack.MsgOptionText(text, false), slack.MsgOptionPostMessageParameters(msgParams))
			if err != nil {
				mod.Logf("Error posting message to the slack channel %s: %s", to, err)
			}
		}
	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1127877
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
}
93423
func (mod *OpenweathermapBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "get_current_weather":
		var location string
		action.Options.Bind("location", &location)

		err := mod.current.CurrentByName(location)
		if err != nil {
			mod.LogErrorf("Failed to fetch weather: %v", err)
			return nil
		}

		mod.TriggerCurrentWeatherEvent()

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
560170
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
}
247032
func (c *Context) Action(ctl string, act string) (err error) {
	a := c.Module.Wrapper(`controller.` + ctl)
	if a == nil {
		return c.Atoe(`Controller "` + ctl + `" does not exist.`)
	}
	k := `webx.controller.reflect.type:` + ctl
	var e reflect.Type
	if t, ok := c.Get(k).(reflect.Type); ok {
		e = t
	} else {
		e = reflect.Indirect(reflect.ValueOf(a.Controller)).Type()
		c.Set(k, e)
	}
	return a.Exec(c, e, act)
}
1328357
func (w *Ware) Action(handler Handler) {
	validateHandler(handler)
	w.action = handler
}
246592
func (mod *JenkinsBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}
	switch action.Name {
	case "trigger":
		jobname := ""
		action.Options.Bind("job", &jobname)

		mod.triggerBuild(jobname)

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}
	return outs
}
458314
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
}
804426
func (s *AliasService) Action(action ...AliasAction) *AliasService {
	s.actions = append(s.actions, action...)
	return s
}
42977
func (f *Facade) FinishActions(args params.ActionExecutionResults) params.ErrorResults {
	actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
	return common.FinishActions(args, actionFn)
}
709612
func (f *RaceFreeFakeWatcher) Action(action EventType, obj runtime.Object) {
	f.Lock()
	defer f.Unlock()
	if !f.Stopped {
		select {
		case f.result <- Event{action, obj}:
			return
		default:
			panic(fmt.Errorf("channel full"))
		}
	}
}
1264283
func (mod *TwilioBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		body := ""
		action.Options.Bind("body", &body)

		_, err := twilio.NewMessage(mod.client, mod.fromNumber, mod.toNumber, twilio.Body(body))
		if err != nil {
			mod.LogErrorf("Error sending twilio SMS: %s", err)
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
973941
func (st *State) matchingActions(ar ActionReceiver) ([]Action, error) {
	return st.matchingActionsByReceiverId(ar.Tag().Id())
}
158361
func (c *Client) FindActionTagsByPrefix(arg params.FindTags) (params.FindTagsResults, error) {
	results := params.FindTagsResults{}
	err := c.facade.FacadeCall("FindActionTagsByPrefix", arg, &results)
	return results, err
}
1364680
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
}
261234
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
}