// TriggerEvent ...
542523
func TriggerEvent(name TriggerEventName, payload interface{}) error {
	// Create plugin input
	payloadBytes, err := json.Marshal(payload)
	if err != nil {
		return err
	}

	pluginInput := PluginInput{
		PluginInputPayloadKey:      string(payloadBytes),
		PluginInputTriggerEventKey: string(name),
	}

	// Load plugins
	plugins, err := LoadPlugins(string(name))
	if err != nil {
		return err
	}

	// Run plugins
	for _, plugin := range plugins {
		if err := RunPluginByEvent(plugin, pluginInput); err != nil {
			return err
		}
	}

	return nil
}
1181785
func (s *Application) AddEvent(eventName string, handler interface{}) *Application {
	if h, ok := handler.(func(func(bool), ...interface{})); ok {
		events.AddEvent(eventName, h)
		return s
	}
	if h, ok := handler.(func(...interface{}) bool); ok {
		events.AddEvent(eventName, func(next func(bool), sessions ...interface{}) {
			next(h(sessions...))
		})
		return s
	}
	s.Core.Logger().Warnf(`Invalid event function: %T`, handler)
	return s
}
645372
func (h EventHandlerFunc) HandleEvent(ctx context.Context, e Event) error {
	return h(ctx, e)
}
493904
func (c *Client) SendEvent(event Event, opts ...interface{}) (res StatusMessageRes, err error) {
	return c.SendEvents([]Event{event}, opts...)
}
1328596
func (b *Button) OnKeyEvent(ev KeyEvent) {
	if !b.IsFocused() {
		return
	}
	if ev.Key == KeyEnter && b.onActivated != nil {
		b.onActivated(b)
	}
}
759343
func NewEvent(category string, action string) *Event {
	h := &Event{
		category: category,
		action:   action,
	}
	return h
}
1163828
func (_m *DBClient) AddEvent(e models.Event) (string, error) {
	ret := _m.Called(e)

	var r0 string
	if rf, ok := ret.Get(0).(func(models.Event) string); ok {
		r0 = rf(e)
	} else {
		r0 = ret.Get(0).(string)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(models.Event) error); ok {
		r1 = rf(e)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1028482
func (il *ILertNotifier) sendEvent(event iLertEvent) error {
	body, err := json.Marshal(event)
	if err != nil {
		return err
	}

	res, err := http.Post(apiEndpoint, "application/json", bytes.NewBuffer(body))
	if err != nil {
		return err
	}

	defer res.Body.Close()

	if res.StatusCode != 200 {
		body, _ := ioutil.ReadAll(res.Body)
		return errors.New(fmt.Sprintf("Unexpected HTTP status code: %d (%s)", res.StatusCode, string(body)))
	}

	return nil
}
259305
func NewEvent(event interface{}, sourceURL string) *Event {
	return &Event{
		SourceURL: sourceURL,
		Event:     event,
	}
}
349396
func (filterHandler *FilterHandler) Event(logEvent *event.Event) error {
	for _, filterFunc := range filterHandler.filterFuncs {
		if !filterFunc(logEvent) {
			return nil
		}
	}
	return filterHandler.nextHandler.Event(logEvent)
}
328674
func (e *EventServer) processEvent(ctx context.Context, eventInfo *common.EventInfo) (err error) {

	if e.registerer == nil {
		return fmt.Errorf("No registered handlers")
	}

	f, err := e.registerer.GetHandler(eventInfo.PUType, eventInfo.EventType)
	if err != nil {
		return fmt.Errorf("Handler not found: %s", err)
	}

	return f(ctx, eventInfo)
}
1327500
func NoopTrigger(id, data string) Trigger {
	return Trigger{
		Id:      id,
		Payload: &Trigger_Noop{Noop: &api.NoopTrigger{Data: data}},
	}
}
960290
func (s *QueueConfigurationDeprecated) SetEvent(v string) *QueueConfigurationDeprecated {
	s.Event = &v
	return s
}
771329
func (_m *DBClient) UpdateEvent(e models.Event) error {
	ret := _m.Called(e)

	var r0 error
	if rf, ok := ret.Get(0).(func(models.Event) error); ok {
		r0 = rf(e)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
970712
func (e *EventSub) TriggerMatch(h Event) {
	// if e.dom != nil
	if strings.ToLower(h.Type()) != strings.ToLower(e.Type()) {
		return
	}

	//get the current event target
	target := h.Target()

	// log.Printf("target -> %+s", target)

	//get the targets parent
	// parent := target.Get("parentElement")
	parent := e.dom

	var match bool

	children := parent.Call("querySelectorAll", e.Target())

	if children == nil || children == js.Undefined {
		return
	}

	// log.Printf("children -> %s  -> %t %t", children, children == nil, children == js.Undefined)

	//get all possible matches of this query
	// posis := parent.QuerySelectorAll(e.EventSelector())
	posis := jsutils.DOMObjectToList(children)

	// log.Printf("Checking: %s for %s -> %+s", target, e.ID(), posis)

	//is our target part of those that match the selector
	for _, item := range posis {
		// log.Printf("taget %+s and item %+s -> %t", target, item, target == item)
		if item != target {
			continue
		}
		match = true
		break
	}

	//if we match then run the listeners registered
	if match {
		//if we dont want immediatepropagation kill it else check propagation also
		if e.StopImmediatePropagation() {
			h.StopImmediatePropagation()
		} else {
			//if we dont want propagation kill it
			if e.StopPropagation() {
				h.StopPropagation()
			}
		}

		//we want to PreventDefault then stop default action
		if e.PreventDefault() {
			h.PreventDefault()
		}

		e.HandleContext(h)
	}
}
315537
func (f EventHandlerFunc) HandleEvent(resp http.ResponseWriter, req *http.Request, event *Event) {
	f(resp, req, event)
}
760377
func (s *Service) TriggerEventHandler(queryChat bool, bsonQuery map[string]interface{}, data interface{}) error {

	if s.EventHandler == nil {
		return fmt.Errorf("EventHandler missed for %s service", s.Name)
	}

	if bsonQuery == nil {
		return nil
	}

	db := mongoSession.Clone().DB(mongo.Database)
	defer db.Session.Close()

	ctx := &Context{db: db, ServiceName: s.Name}
	atLeastOneWasHandled := false

	if queryChat {
		chats, err := ctx.FindChats(bsonQuery)

		if err != nil {
			s.Log().WithError(err).Error("FindChats error")
		}
		for _, chat := range chats {
			if chat.Deactivated || chat.BotWasKickedOrStopped() {
				continue
			}
			ctx.Chat = chat.Chat
			err := s.EventHandler(ctx, data)

			if err != nil {
				ctx.Log().WithError(err).Error("EventHandler returned error")
			} else {
				atLeastOneWasHandled = true
			}
		}
	} else {
		users, err := ctx.FindUsers(bsonQuery)

		if err != nil {
			s.Log().WithError(err).Error("findUsers error")
		}

		for _, user := range users {
			ctx.User = user.User
			ctx.User.ctx = ctx
			ctx.Chat = Chat{ID: user.ID, ctx: ctx}
			err := s.EventHandler(ctx, data)

			if err != nil {
				ctx.Log().WithError(err).Error("EventHandler returned error")
			} else {
				atLeastOneWasHandled = true
			}
		}
	}

	if !atLeastOneWasHandled {
		return errors.New("No single chat was handled")
	}
	return nil
}