Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@devth
Last active March 17, 2019 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devth/665acc1dc38977c5bae4f7362924012d to your computer and use it in GitHub Desktop.
Save devth/665acc1dc38977c5bae4f7362924012d to your computer and use it in GitHub Desktop.

Yetibot usage fundamentals

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:

  1. list used to build up a list of memes
  2. random to select a random meme from the list
  3. meme to generate a meme
  4. sub expression to randomly choose from "should", "should not", "must" and "must not
  5. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment