discljord.events.middleware
Contains functions for constructing middleware, and some default middleware.
Middleware for discljord event handlers allow the modification and filtration
of events to be sent along to event handlers. Following is an example of an
identity middleware, and can be used as an example of what middleware in
discljord look like.
```clojure
(defn identity-middleware
"Middleware that passes through events unchanged."
[handler]
(fn [event-type event-data & more]
(apply handler event-type event-data more)))
```
concat
(concat handler)
Takes a handler function and creates a middleware which concats the handlers.
The events in the handler function passed are always run before the ones that
are given to the middleware when it is applied.
data-mapping
(data-mapping f)
Makes a transform function for use with [[map]] that operates on event-data.
The resulting function is from a vector of event-type and event-data to a
vector of event-type and event-data. The event-type is passed through without
change, and event-data is transformed by `f`.
filter
(filter pred)
Makes middleware that only calls the handler if `pred` returns truthy.
`pred` is a predicate expected to take the event-type and event-data.
ignore-bot-messages
Middleware which won't call the handler if the event is a message from a bot.
log-when
(log-when filter)
Takes a predicate and if it returns true, logs the event before passing it on.
The predicate must take the event-type and the event-data, and return a truthy
value if it should log. If the value is a valid level at which to log, that
logging level will be used.
map
(map f)
Makes a middleware which runs `f` over events before passing to the handler.
`f` is a function of a vector of event-type and event-data to a vector of
event-type and event-data which are then passed to the handler.
transduce
(transduce xf)
Makes a middleware which takes a transducer and runs it over event-data.