.. _command-parsing-primer: ====================== Command parsing primer ====================== This page discusses some of the details and features in Limnoria's command parser, such as the ability to nest commands. This is mainly useful when building :ref:`custom commands ` or message triggers using the :ref:`Aka ` and :ref:`MessageParser ` plugins. .. _quoting-commands: Quoting command arguments ------------------------- In most cases, commands are simple enough that their arguments don't need to be quoted:: @echo hello world hello world However, when a command takes in multiple strings, you will have to quote multi-word inputs to prevent them from being split:: # wrong @sample 1 hello hi what's up what's # right @sample 1 "hello" "hi" "what's up" hello Similarly, if a text argument includes ``"``, ``[``, or ``]``, you'll have to quote it and escape any double quotes:: @len "waiter, there's a \" in my soup!" 31 @echo "test" "test" test test @echo "\"test\" \"test\"" "test" "test" You can use quotes to express an empty argument:: @format replace a "" abacadabra bcdbr And also to expand non-printable characters:: @echo \x0308hello world \x0308hello world @echo "\x0308hello world" # this text would be yellow on IRC hello world .. _nested-commands: Nested commands --------------- Commands can be nested in Limnoria by surrounding them in square brackets. This example runs some text through two commands from the :ref:`Filter ` plugin:: @caps [filter reverse hello world] DLROW OLLEH Similarly, the output of multiple commands can be combined using :ref:`echo ` or :ref:`reply `. The below command flips two coins using the :ref:`plugin-games` plugin:: @echo [coin] [coin] heads tails @reply [coin] [coin] jlu5: heads heads There are a few differences between ``echo`` and ``reply``: - ``reply`` always prefixes the output with the caller's nick, while ``echo`` does not. - ``echo`` supports standard substitutions, such as ``$nick``, ``$version``, etc., while ``reply`` does not Note that the bot will always add spaces around the output of a nested command. To work around this, you may want to use the :ref:`concat ` command to join two outputs without a space:: @echo Random percent value: [dice 1d100]% Random percent value: 56 % @echo Random percent value: [concat [dice 1d100]%] Random percent value: 78% The above example shows how commands can be nested more than once as well; this limit is controlled by the :ref:`config option ` ``commands.nested.maximum``.