Instead of working through Yetibot's primitives and its many individual
capabilities we'll start with a non trivial expression that's made up of several
levels of nested aliases composed of piped commands. This will better illustrate
how such primitives can be combined into something useful fun.
!yetishould
To start unpacking this we can use help
:
!help yetishould
Help shows us that it's an alias for an expression:
TODO
- allow multiline yetibot expressions
list batman insanity kahn gasp
| random
| meme %s: yetibot
`list should, should not, must, must not | random`
`randshould`
Out of the commands in that expression we can see:
- list used to build up a list of memes
- random to select a random meme from the list
- meme to generate a meme
- sub expression to randomly choose from "should", "should not", "must" and "must not
- randshould, which is itself an alias.
Let's unpack randshould
:
!help randshould
randshould # alias for randletter | complete should i | random | sed s/should i/ | trim
Unpack its contents:
!help randletter
randletter # alias for range 65 91 | xargs echo | random | js String.fromCharCode(%s)
Finally we have expanded all the way down to built in commands. Let's take a look at each one:
!help range
range <end> # create a list from 0 to <end> (exclusive)
range <start> <end> # create a list from <start> (inclusive) to <end> (exclusive)
range <start> <end> <step> # create a list from <start> (inclusive) to <end> (exclusive) by <step>
Examples:
range 2 => 0 1
range 2 4 => 2 3
range 0 6 2 => 0 2 4
Results are returned as collections.
!help xargs
xargs <cmd> <list> # run <cmd> for every item in <list> in parallel; behavior is
similar to xargs(1)'s xargs -n1
!help random
random <list> # returns a random item from <list>
random # generate a random number
!help sed
sed s/<search-pattern>/<replace-pattern> <string> # replace <search-pattern>
with <replace-pattern> on piped contents
sed s/<search-pattern/ <string> # replace <search-pattern> with nothing on piped
contents