3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-22 20:09:43 +01:00

doc/Factoids.md: improve expansion-modifiers section

This commit is contained in:
Pragmatic Software 2020-06-03 01:15:35 -07:00
parent 5d10836dd3
commit 0bd53cfd87

View File

@ -383,16 +383,16 @@ Another example, creating the RTFM trigger:
### Expansion modifiers ### Expansion modifiers
List `$variables` and [Selectors](Commands.md#selectors) can accept trailing expansion modifier keywords prefixed with a colon. These can be chained together to combine their effects. List `$variables` and [Selectors](Commands.md#selectors) can accept trailing expansion modifier keywords prefixed with a colon. These can be chained together to combine their effects.
There are two categories of expansion modifiers. Selection modifiers and text modifiers. There are three categories of expansion modifiers. Selector, Selection and text modifiers.
Selection modifiers control how values are chosen from the `$variable` or Selector list. Selector modifiers control how values are chosen from the `$variable` or Selector list.
<pragma-> !echo $colors:pick(3) <pragma-> !echo $colors:pick(3)
<PBot> red pink green <PBot> red pink green
Note that modifiers may not contain spaces. `:pick(2, 3)` is invalid and must be written as `:pick(2,3)`. Note that modifiers may not contain spaces. `:pick(2, 3)` is invalid and must be written as `:pick(2,3)`.
Modifier | Description Selector Modifier | Description
--- | --- --- | ---
`:<channel>` | Looks for variable in `<channel>` first; use `global` to refer to the global channel. This modifier must be the first modifier when chained with other modifiers. `:<channel>` | Looks for variable in `<channel>` first; use `global` to refer to the global channel. This modifier must be the first modifier when chained with other modifiers.
`:index(n)` | Selects the `n`th element from the `$variable` list. `:index(n)` | Selects the `n`th element from the `$variable` list.
@ -401,24 +401,9 @@ Modifier | Description
`:pick_unique(x)` | Selects `x` count of random elements without any repeated selections. `:pick_unique(x)` | Selects `x` count of random elements without any repeated selections.
`:pick_unique(x,y)` | Selects between `x` and `y`, inclusive, count of random elements without any repeated selections. `x` may be `0` to occasionally pick no value. In this case the `$variable` and any leading whitespace will be stripped. `:pick_unique(x,y)` | Selects between `x` and `y`, inclusive, count of random elements without any repeated selections. `x` may be `0` to occasionally pick no value. In this case the `$variable` and any leading whitespace will be stripped.
Text modifiers alter the selected values. Selection modifiers apply only to selector modifiers that return more than one selection. Using them otherwise has no effect.
<pragma-> !echo $colors:uc Selection Modifier | Description
<PBot> RED
<pragma-> !echo $colors:ucfirst
<PBot> Blue
Modifier | Description
--- | ---
`:uc` | Uppercases the expansion.
`:lc` | Lowercases the expansion.
`:ucfirst` | Uppercases the first letter in the expansion.
`:title` | Lowercases the expansion and then uppercases the initial letter of each word.
The following text modifiers apply only to selection modifiers that return more than one selection. Using them otherwise has no effect.
Modifier | Description
--- | --- --- | ---
`:sort` | Sorts the selected list in ascending order. `:sort` | Sorts the selected list in ascending order.
`:-sort` | Sorts the selected list in descending order. `:-sort` | Sorts the selected list in descending order.
@ -431,6 +416,21 @@ Modifier | Description
<pragma-> !echo $colors:pick(5):enumerate <pragma-> !echo $colors:pick(5):enumerate
<PBot> blue, green, dark purple, orange and bright yellow <PBot> blue, green, dark purple, orange and bright yellow
And finally, text modifiers alter the selected values.
<pragma-> !echo $colors:uc
<PBot> RED
<pragma-> !echo $colors:ucfirst
<PBot> Blue
Text Modifier | Description
--- | ---
`:uc` | Uppercases the expansion.
`:lc` | Lowercases the expansion.
`:ucfirst` | Uppercases the first letter in the expansion.
`:title` | Lowercases the expansion and then uppercases the initial letter of each word.
## action_with_args ## action_with_args
You can use the [`factset`](#factset) command to set a special [factoid metadata](#factoid-metadata) key named `action_with_args` to trigger an alternate message if an argument has been supplied. You can use the [`factset`](#factset) command to set a special [factoid metadata](#factoid-metadata) key named `action_with_args` to trigger an alternate message if an argument has been supplied.