Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions apps/website/content/docs/plugins/plugin-discord/parsers/embed.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,115 @@
---
title: EmbedParser
---

import { Callout } from 'fumadocs-ui/components/callout';
import { Tabs } from 'fumadocs-ui/components/tabs';

The embed tag creates Discord embeds that can be sent along with messages.
There are two ways to use the embed tag: either by using properly formatted embed JSON or by manually inputting the accepted embed properties.

## Usage

<Tabs items={['ESM', 'CommonJs']}>
```ts showLineNumbers tab="ESM"
import { Interpreter } from 'tagscript';
import { EmbedParser } from '@tagscript/plugin-discord';
const ts = new Interpreter(new EmbedParser());
```
```js showLineNumbers tab="CommonJs"
const { Interpreter } = require('tagscript');
const { EmbedParser } = require('@tagscript/plugin-discord');
const ts = new Interpreter(new EmbedParser());
```
</Tabs>

## API

Check [EmbedParser](../../../typedoc-api/@tagscript/plugin-discord/classes/EmbedParser) for the API documentation.

## For End Users

<Callout type="info" emoji={null}>
### Syntax

**Using JSON:**
```yaml
{embed:json}
```

**Using properties:**
```yaml
{embed(property):value}
```

### Examples

**JSON Format:**
```yaml
{embed:{"title": "Hello!", "description": "This is a test embed."}}
```

```yaml
{embed:{
"title": "Here's a random duck!",
"image": {"url": "https://random-d.uk/api/randomimg"},
"color": 15194415
}}
```

**Property Format:**
```yaml
{embed(color):0x37b2cb}
{embed(title):Rules}
{embed(description):Follow these rules to ensure a good experience in our server!}
{embed(field):Rule 1|Respect everyone you speak to.|false}
```

```yaml
{embed(author):Author Name}
{embed(thumbnail):https://example.com/image.png}
{embed(footer):Footer text}
{embed(timestamp):true}
```

### Available Properties

- `title` - The embed title
- `description` - The embed description
- `color` - The embed color (hex code or number)
- `author` - The embed author name
- `thumbnail` - URL for the thumbnail image
- `image` - URL for the main image
- `footer` - The footer text
- `timestamp` - Set to `true` to add current timestamp
- `field` - Add a field with format: `name|value|inline`

### Field Format

Fields use the format: `{embed(field):name|value|inline}`
- `name` - The field name
- `value` - The field value
- `inline` - `true` or `false` for inline display

### Notes

- Multiple embed tags in the same TagScript will merge properties
- Color values can be hex codes (0x37b2cb) or decimal numbers
- JSON format allows for more complex embed structures
- Developers need to construct the embed builder with the parser output

</Callout>

## Developer Example

```ts showLineNumbers
import { Interpreter } from 'tagscript';
import { EmbedParser } from '@tagscript/plugin-discord';
import { EmbedBuilder } from 'discord.js';

const ts = new Interpreter(new EmbedParser());
const result = await ts.run('{embed:{"title": "Hello!", "description": "This is a test embed."}}');

// You might need to modify the embed object before passing to EmbedBuilder
const embed = new EmbedBuilder(result.actions.embed);
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ description: Tagscript parsers are used to parse a tag and return a value based

Discord Plugin provides the following parsers which you can use to parse tags.

- [EmbedParser](/plugins/plugin-discord/parsers)
- [EmbedParser](/plugins/plugin-discord/parsers/embed)
62 changes: 62 additions & 0 deletions apps/website/content/docs/tagscript/parsers/fifty-fifty.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: FiftyFiftyParser
---

import { Callout } from 'fumadocs-ui/components/callout';
import { Tabs } from 'fumadocs-ui/components/tabs';

The fifty-fifty tag has a 50% chance of returning the payload, and a 50% chance of returning an empty string.
This parser is useful for creating random events or decisions with equal probability.

## Usage

<Tabs items={['ESM', 'CommonJs']}>
```ts showLineNumbers tab="ESM"
import { Interpreter, FiftyFiftyParser } from 'tagscript';
const ts = new Interpreter(new FiftyFiftyParser());
```
```js showLineNumbers tab="CommonJs"
const { Interpreter, FiftyFiftyParser } = require('tagscript');
const ts = new Interpreter(new FiftyFiftyParser());
```
</Tabs>

## API

Check [FiftyFiftyParser](../../typedoc-api/tagscript/classes/FiftyFiftyParser) for the API documentation.

## For End Users

<Callout type="info" emoji={null}>
### Syntax
```yaml
{5050:message}
{50:message}
{?:message}
```

### Examples

```yaml
{5050:You got lucky!}
# 50% chance: You got lucky!
# 50% chance: (empty string)
```

```yaml
I pick {if({5050:.}!=):heads|tails}
# 50% chance: I pick heads
# 50% chance: I pick tails
```

```yaml
{?:Rare event occurred!} Welcome to the server!
# 50% chance: Rare event occurred! Welcome to the server!
# 50% chance: Welcome to the server!
```

### Aliases

`5050`, `50`, `?`

</Callout>
8 changes: 7 additions & 1 deletion apps/website/content/docs/tagscript/parsers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ Parsers are used to parse a tag and return a value based on the tag. You can use
Following is the list of builtin parsers:

- [BreakParser](/tagscript/parsers/break)
- [FiftyFiftyParser](/tagscript/parsers/fifty-fifty)
- [IfStatementParser](/tagscript/parsers/if-statement)
- [UnionStatementParser](/tagscript/parsers/union-statement)
- [IntersectionStatementParser](/tagscript/parsers/intersection-statement)
- [RandomParser](/tagscript/parsers/random)
- [RangeParser](/tagscript/parsers/range)
- [ReplaceParser](/tagscript/parsers/replace)
- [SliceParser](/tagscript/parsers/slice)
- [StopParser](/tagscript/parsers/stop)
- [UnionStatementParser](/tagscript/parsers/union-statement)

## Custom Parser

Expand Down
6 changes: 6 additions & 0 deletions apps/website/content/docs/tagscript/parsers/meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"break": "Break Parser",
"fifty-fifty": "FiftyFifty Parser",
"if-statement": "If Statement Parser",
"intersection-statement": "Intersection Statement Parser",
"random": "Random Parser",
"range": "Range Parser",
"replace": "Replace Parser",
"slice": "Slice Parser",
"stop": "Stop Parser",
"union-statement": "Union Statement Parser"
}
65 changes: 65 additions & 0 deletions apps/website/content/docs/tagscript/parsers/random.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: RandomParser
---

import { Callout } from 'fumadocs-ui/components/callout';
import { Tabs } from 'fumadocs-ui/components/tabs';

The random tag picks a random item from a list of strings, split by either `~` or `,`.
This parser is useful for selecting random messages, responses, or values from a predefined list.

## Usage

<Tabs items={['ESM', 'CommonJs']}>
```ts showLineNumbers tab="ESM"
import { Interpreter, RandomParser } from 'tagscript';
const ts = new Interpreter(new RandomParser());
```
```js showLineNumbers tab="CommonJs"
const { Interpreter, RandomParser } = require('tagscript');
const ts = new Interpreter(new RandomParser());
```
</Tabs>

## API

Check [RandomParser](../../typedoc-api/tagscript/classes/RandomParser) for the API documentation.

## For End Users

<Callout type="info" emoji={null}>
### Syntax
```yaml
{random:item1,item2,item3}
{random:item1~item2~item3}
```

### Examples

```yaml
{random:foo, bar, baz}
# foo
# bar
# baz
```

```yaml
{random:Hello, Hi, Hey} there!
# Hello there!
# Hi there!
# Hey there!
```

```yaml
{random:apple~banana~cherry~date}
# apple
# banana
# cherry
# date
```

### Aliases

`rand`

</Callout>
69 changes: 69 additions & 0 deletions apps/website/content/docs/tagscript/parsers/range.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: RangeParser
---

import { Callout } from 'fumadocs-ui/components/callout';
import { Tabs } from 'fumadocs-ui/components/tabs';

The range tag picks a random number from a range of numbers separated by `-` or `,`.
The number range is inclusive, so it can pick the starting/ending number as well.
Using the `rangef` tag will pick a number to the tenth decimal place for floating-point values.

## Usage

<Tabs items={['ESM', 'CommonJs']}>
```ts showLineNumbers tab="ESM"
import { Interpreter, RangeParser } from 'tagscript';
const ts = new Interpreter(new RangeParser());
```
```js showLineNumbers tab="CommonJs"
const { Interpreter, RangeParser } = require('tagscript');
const ts = new Interpreter(new RangeParser());
```
</Tabs>

## API

Check [RangeParser](../../typedoc-api/tagscript/classes/RangeParser) for the API documentation.

## For End Users

<Callout type="info" emoji={null}>
### Syntax
```yaml
{range:min-max}
{range:min,max}
{rangef:min-max}
{rangef:min,max}
```

### Examples

```yaml
{range:1-10}
# 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10
```

```yaml
Your lucky number is {range:10-30}!
# Your lucky number is 14!
# Your lucky number is 25!
```

```yaml
{rangef:5.0-7.0}
I am guessing your height is {rangef:5-7}ft.
# I am guessing your height is 5.3ft.
# I am guessing your height is 6.8ft.
```

```yaml
Dice roll: {range:1,6}
# Dice roll: 4
```

### Aliases

`rangef` (for floating-point numbers)

</Callout>
Loading
Loading