> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mira.lgbt/llms.txt
> Use this file to discover all available pages before exploring further.

# Pipes and operators

> Change values, run conditions, do maths, and pick things at random.

There are two ways to change a value, and they look different.

A **pipe** goes inside a placeholder, after a `|`, and changes whatever that placeholder gives back.

```text Pipe theme={null}
{server.member_count|comma}
```

```text Result theme={null}
1,234
```

An **operator** is its own node and works on whatever you put after the `:`, whether that's
text you typed or another placeholder.

```text Operator theme={null}
{fmt: 71437}
{fmt: {server.member_count}}
```

```text Result theme={null}
71,437
1,234
```

Several names exist as both. Use the pipe when you already have a placeholder, and the operator
when you're working with plain text or nesting things.

## Pipes

```text Syntax theme={null}
{placeholder|pipe}
{placeholder|pipe: args}
```

| Pipe         | Aliases     | Args              | Description                      | Example                                         |
| ------------ | ----------- | ----------------- | -------------------------------- | ----------------------------------------------- |
| `upper`      | `u`         | None              | Makes it uppercase               | `{member.name\|upper}` → `HELLOFAMAN`           |
| `lower`      | `l`         | None              | Makes it lowercase               | `{member.name\|lower}` → `hellofaman`           |
| `title`      | `t`         | None              | Capitalises each word            | `{member.name\|title}` → `Hellofaman`           |
| `capitalize` | `cap`       | None              | Capitalises the first letter     | `{member.name\|cap}` → `Hellofaman`             |
| `length`     | `len`       | None              | Counts the characters            | `{member.name\|len}` → `10`                     |
| `comma`      | `fmt`       | None              | Adds separators to big numbers   | `{server.member_count\|comma}` → `1,234`        |
| `ordinal`    | `ord`       | None              | Turns a number into a position   | `{member.join_position\|ordinal}` → `2nd`       |
| `plural`     | `plur`, `p` | `singular,plural` | Picks a word based on the number | `{server.member_count\|plural: member,members}` |

## Operators

```text Syntax theme={null}
{operator: value}
```

### Logic

Use these to change what a message says depending on the situation.

#### if

```text Syntax theme={null}
{if: condition && value if true && value if false}
```

Shows the first value when the condition passes, and the second when it doesn't. You can
compare with `==`, `!=`, `>`, `<`, `>=`, and `<=`.

```text Examples theme={null}
{if: {member.top_role} && Your top role is {member.top_role} && You don't have any roles yet}
{if: {server.member_count}>100 && Big server && Small server}
```

#### unless

```text Syntax theme={null}
{unless: condition && value if true && value if false}
```

The opposite of `if`. Shows the first value when the condition is **empty or false**.

```text Example theme={null}
{unless: {member.top_role} && No roles yet && Has roles}
```

#### default

```text Syntax theme={null}
{default: value, fallback}
```

Shows the value if there is one, and the fallback if there isn't.

```text Example theme={null}
{default: {member.top_role}, No roles}
```

<Warning>
  Watch the separators. `if` and `unless` split their parts with `&&`, but `default` splits with
  a **comma**. Using the wrong one leaves the whole node showing as raw text.
</Warning>

### Maths

| Operator | Syntax         | Description                        | Example                                   |
| -------- | -------------- | ---------------------------------- | ----------------------------------------- |
| `add`    | `{add: 10+5}`  | Adds the numbers together          | `{add: {server.member_count}+10}` → `54`  |
| `sub`    | `{sub: 10-5}`  | Takes the rest away from the first | `{sub: 100-{server.member_count}}` → `56` |
| `mul`    | `{mul: 10+5}`  | Multiplies them together           | `{mul: {server.member_count}+2}` → `88`   |
| `div`    | `{div: 100+5}` | Divides the first by the rest      | `{div: 100+{server.member_count}}` → `2`  |
| `floor`  | `{floor: 4.7}` | Rounds down                        | `{floor: 4.7}` → `4`                      |
| `ceil`   | `{ceil: 4.2}`  | Rounds up                          | `{ceil: 4.2}` → `5`                       |
| `round`  | `{round: 4.5}` | Rounds to the nearest              | `{round: 4.5}` → `5`                      |

Numbers are separated with `+`, except `sub`, which uses `-`.

```text Countdown to a milestone theme={null}
{sub: 2000-{server.member_count}} more members until 2k!
```

### Text

These work on text you type, or on a placeholder you nest inside them.

| Operator     | Aliases | Description                      | Example                                                     |
| ------------ | ------- | -------------------------------- | ----------------------------------------------------------- |
| `upper`      | `u`     | Makes it uppercase               | `{upper: hello world}` → `HELLO WORLD`                      |
| `lower`      | `l`     | Makes it lowercase               | `{lower: HELLO}` → `hello`                                  |
| `capitalize` | `cap`   | Capitalises the first character  | `{cap: hello}` → `Hello`                                    |
| `length`     | `len`   | Counts the characters            | `{len: hello}` → `5`                                        |
| `comma`      | `fmt`   | Adds separators to big numbers   | `{fmt: 71437}` → `71,437`                                   |
| `ordinal`    | `ord`   | Turns a number into a position   | `{ord: 3}` → `3rd`                                          |
| `plural`     | `plur`  | Picks a word based on the number | `{plural: {server.member_count}: person,people}` → `people` |
| `plural`     | `plur`  | Adds an `s` when it needs one    | `{plural: {server.member_count}}` → `s` or nothing          |

<Tip>
  `plural` on its own is the quick version. `{server.member_count} member{plural:   {server.member_count}}` reads correctly whether there's one member or a thousand.
</Tip>

### Random

| Operator  | Aliases               | Syntax             | Description                                          |
| --------- | --------------------- | ------------------ | ---------------------------------------------------- |
| `random`  | `rand`, `r`, `choice` | `{random: a,b,c}`  | Picks one of the options                             |
| `randint` | `rng`, `ri`           | `{randint: 1,100}` | Picks a whole number between the two, including both |

```text Examples theme={null}
{random: Welcome,Hello,Sup,Hey}
{randint: 1,100}
{color: {random: #BAEBAE, #EFAEFA}}
{sticker: {r: wave, heya, sup}}
```

## What counts as empty

`if`, `unless`, and `default` all treat these as empty:

| Value                      | Notes                                   |
| -------------------------- | --------------------------------------- |
| Nothing at all             | An empty value                          |
| `0`                        |                                         |
| `false`                    |                                         |
| `None` or `null`           |                                         |
| A node that didn't resolve | Left as raw text, so it counts as empty |

Everything else counts as having a value.
