Functions

September 15, 2021 ยท View on GitHub

Functions are commands that accept input, manipulate it and then output the result. They are extremely useful with piping or command substituting.

For example, the uri_escape function demonstrated in the Substitution section earlier makes text safe for use in a URL. We also saw the sed and uc functions demonstrated in Piping.

<pragma-> uri_escape thing's & words
   <PBot> thing%27s%20%26%20words

As demonstrated previously, the sed function replaces text using a substitution regex. The uc function uppercases the text.

<pragma-> echo Hello world! | {sed s/world/universe/} | {uc}
   <PBot> HELLO UNIVERSE!

Here's a short list of the Functions that come with PBot.

NameDescription
uri_escapePercent-encodes unsafe URI characters.
sedPerforms sed-like regex substitution.
grepSearches a string, using a regex, and prints the matching whole-word (e.g. echo pizza hamburger hotdog | {grep burger} outputs hamburger).
pluralizeIntelligently makes a word or phrase plural.
unquoteRemoves surrounding quotation marks.
titleTitle-cases text. That is, lowercases the text then uppercases the first letter of each word.
ucfirstUppercases the first character of the text.
ucUppercases all characters.
lcLowercases all characters.

Additional Functions can be loaded via PBot Plugins. For examples, see Plugin/FuncBuiltins.pm and Plugin/FuncGrep.pm.