The command namespace contains functions to create command handlers and dispatch commands.
The command namespace contains functions to create command handlers and dispatch commands.
(defhandler symbol pattern interaction-binding options & body)Utility macro for (def my-handler (handler ...)) (see handler)
Utility macro for `(def my-handler (handler ...))` (see [[handler]])
(defpaths symbol & handlers)Utility macro for (def symbol (paths handlers)) (see paths)
Utility macro for `(def symbol (paths handlers))` (see [[paths]])
(dispatch handlers interaction)A function to dispatch a command to a list of handlers.
Takes two arguments: handlers (a list of command handler functions) and interaction,
the interaction of a command execution.
Each handler will be run until one is found that does not return nil.
A function to dispatch a command to a list of handlers. Takes two arguments: `handlers` (a list of command handler functions) and `interaction`, the interaction of a command execution. Each handler will be run until one is found that does not return `nil`.
(group prefix & handlers)A macro to combine multiple handlers into one under a common prefix.
prefix is a pattern like in handler.
handlers are command handler functions.
A macro to combine multiple handlers into one under a common prefix. `prefix` is a pattern like in [[handler]]. `handlers` are command handler functions.
(handler pattern interaction-binding options & body)A macro to generate a command handler that will accept commands matching the given pattern.
pattern is a vector of literals (strings) and placeholders (symbols).
Placeholders will match and be bound to any string at that position in the command path.
interaction-binding is a binding that will be bound to the entire interaction object.
options is either a vector, in which case the symbols in that vector will be bound to the options with corresponding names
option-map directly.
body is the command logic. It may access any of the bound symbols above.The function returned by this already has the wrap-options, wrap-check-path and wrap-path middlewares applied.
A macro to generate a command handler that will accept commands matching the given pattern. `pattern` is a vector of literals (strings) and placeholders (symbols). Placeholders will match and be bound to any string at that position in the command path. `interaction-binding` is a binding that will be bound to the entire interaction object. `options` is either a vector, in which case the symbols in that vector will be bound to the options with corresponding names - otherwise, it will be bound to the command's [[option-map]] directly. `body` is the command logic. It may access any of the bound symbols above. The function returned by this already has the [[wrap-options]], [[wrap-check-path]] and [[wrap-path]] middlewares applied.
(option-map command)Returns the options of a command as a map of keywords -> values.
The command is the data associated with an interaction create event of type 2 as Clojure data.
'options' here means the options the user sets, like baz in /foo bar baz: 3, but not bar.
Returns the options of a command as a map of keywords -> values. The command is the data associated with an interaction create event of type 2 as Clojure data. 'options' here means the options the user sets, like `baz` in `/foo bar baz: 3`, but not `bar`.
(path {:keys [name options] :as _command})Given a command, returns the fully qualified command name as a vector.
The command is the data associated with an interaction create event of type 2 as Clojure data. Examples (what the command data represents => what this function returns):
/foo bar baz => ["foo" "bar" "baz"]/foo => ["foo"]Given a command, returns the fully qualified command name as a vector. The command is the data associated with an interaction create event of type 2 as Clojure data. Examples (what the command data represents => what this function returns): - `/foo bar baz` => ["foo" "bar" "baz"] - `/foo` => ["foo"]
(paths & handlers)Function to combine multiple handlers into one by dispatching on them using dispatch.
Function to combine multiple handlers into one by dispatching on them using [[dispatch]].
(wrap-check-path handler path & {:keys [prefix-check?]})Middleware that delegates to the handler only if the command :path matches the given path pattern.
path is a vector of strings (literal matches) and symbols (placeholders that match any value).
Optionally, :prefix-check? true can be set, in which case it will only be checked whether path prefixes the command path.
Must run after wrap-path.
Middleware that delegates to the handler only if the command `:path` matches the given `path` pattern. `path` is a vector of strings (literal matches) and symbols (placeholders that match any value). Optionally, `:prefix-check? true` can be set, in which case it will only be checked whether `path` prefixes the command path. Must run after [[wrap-path]].
(wrap-options handler)Middleware that attaches the :option-map (obtained by option-map) to the command, if not already present.
Middleware that attaches the `:option-map` (obtained by [[option-map]]) to the command, if not already present.
(wrap-path handler)Middleware that attaches the :path (obtained by path) to the command, if not already present.
Middleware that attaches the `:path` (obtained by [[path]]) to the command, if not already present.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |