Skip to content

Commit 7e33401

Browse files
docs: add more docs (#607)
1 parent 3c5ad53 commit 7e33401

File tree

14 files changed

+692
-6
lines changed

14 files changed

+692
-6
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,115 @@
11
---
22
title: EmbedParser
33
---
4+
5+
import { Callout } from 'fumadocs-ui/components/callout';
6+
import { Tabs } from 'fumadocs-ui/components/tabs';
7+
8+
The embed tag creates Discord embeds that can be sent along with messages.
9+
There are two ways to use the embed tag: either by using properly formatted embed JSON or by manually inputting the accepted embed properties.
10+
11+
## Usage
12+
13+
<Tabs items={['ESM', 'CommonJs']}>
14+
```ts showLineNumbers tab="ESM"
15+
import { Interpreter } from 'tagscript';
16+
import { EmbedParser } from '@tagscript/plugin-discord';
17+
const ts = new Interpreter(new EmbedParser());
18+
```
19+
```js showLineNumbers tab="CommonJs"
20+
const { Interpreter } = require('tagscript');
21+
const { EmbedParser } = require('@tagscript/plugin-discord');
22+
const ts = new Interpreter(new EmbedParser());
23+
```
24+
</Tabs>
25+
26+
## API
27+
28+
Check [EmbedParser](../../../typedoc-api/@tagscript/plugin-discord/classes/EmbedParser) for the API documentation.
29+
30+
## For End Users
31+
32+
<Callout type="info" emoji={null}>
33+
### Syntax
34+
35+
**Using JSON:**
36+
```yaml
37+
{embed:json}
38+
```
39+
40+
**Using properties:**
41+
```yaml
42+
{embed(property):value}
43+
```
44+
45+
### Examples
46+
47+
**JSON Format:**
48+
```yaml
49+
{embed:{"title": "Hello!", "description": "This is a test embed."}}
50+
```
51+
52+
```yaml
53+
{embed:{
54+
"title": "Here's a random duck!",
55+
"image": {"url": "https://random-d.uk/api/randomimg"},
56+
"color": 15194415
57+
}}
58+
```
59+
60+
**Property Format:**
61+
```yaml
62+
{embed(color):0x37b2cb}
63+
{embed(title):Rules}
64+
{embed(description):Follow these rules to ensure a good experience in our server!}
65+
{embed(field):Rule 1|Respect everyone you speak to.|false}
66+
```
67+
68+
```yaml
69+
{embed(author):Author Name}
70+
{embed(thumbnail):https://example.com/image.png}
71+
{embed(footer):Footer text}
72+
{embed(timestamp):true}
73+
```
74+
75+
### Available Properties
76+
77+
- `title` - The embed title
78+
- `description` - The embed description
79+
- `color` - The embed color (hex code or number)
80+
- `author` - The embed author name
81+
- `thumbnail` - URL for the thumbnail image
82+
- `image` - URL for the main image
83+
- `footer` - The footer text
84+
- `timestamp` - Set to `true` to add current timestamp
85+
- `field` - Add a field with format: `name|value|inline`
86+
87+
### Field Format
88+
89+
Fields use the format: `{embed(field):name|value|inline}`
90+
- `name` - The field name
91+
- `value` - The field value
92+
- `inline` - `true` or `false` for inline display
93+
94+
### Notes
95+
96+
- Multiple embed tags in the same TagScript will merge properties
97+
- Color values can be hex codes (0x37b2cb) or decimal numbers
98+
- JSON format allows for more complex embed structures
99+
- Developers need to construct the embed builder with the parser output
100+
101+
</Callout>
102+
103+
## Developer Example
104+
105+
```ts showLineNumbers
106+
import { Interpreter } from 'tagscript';
107+
import { EmbedParser } from '@tagscript/plugin-discord';
108+
import { EmbedBuilder } from 'discord.js';
109+
110+
const ts = new Interpreter(new EmbedParser());
111+
const result = await ts.run('{embed:{"title": "Hello!", "description": "This is a test embed."}}');
112+
113+
// You might need to modify the embed object before passing to EmbedBuilder
114+
const embed = new EmbedBuilder(result.actions.embed);
115+
```

apps/website/content/docs/plugins/plugin-discord/parsers/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ description: Tagscript parsers are used to parse a tag and return a value based
77

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

10-
- [EmbedParser](/plugins/plugin-discord/parsers)
10+
- [EmbedParser](/plugins/plugin-discord/parsers/embed)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: FiftyFiftyParser
3+
---
4+
5+
import { Callout } from 'fumadocs-ui/components/callout';
6+
import { Tabs } from 'fumadocs-ui/components/tabs';
7+
8+
The fifty-fifty tag has a 50% chance of returning the payload, and a 50% chance of returning an empty string.
9+
This parser is useful for creating random events or decisions with equal probability.
10+
11+
## Usage
12+
13+
<Tabs items={['ESM', 'CommonJs']}>
14+
```ts showLineNumbers tab="ESM"
15+
import { Interpreter, FiftyFiftyParser } from 'tagscript';
16+
const ts = new Interpreter(new FiftyFiftyParser());
17+
```
18+
```js showLineNumbers tab="CommonJs"
19+
const { Interpreter, FiftyFiftyParser } = require('tagscript');
20+
const ts = new Interpreter(new FiftyFiftyParser());
21+
```
22+
</Tabs>
23+
24+
## API
25+
26+
Check [FiftyFiftyParser](../../typedoc-api/tagscript/classes/FiftyFiftyParser) for the API documentation.
27+
28+
## For End Users
29+
30+
<Callout type="info" emoji={null}>
31+
### Syntax
32+
```yaml
33+
{5050:message}
34+
{50:message}
35+
{?:message}
36+
```
37+
38+
### Examples
39+
40+
```yaml
41+
{5050:You got lucky!}
42+
# 50% chance: You got lucky!
43+
# 50% chance: (empty string)
44+
```
45+
46+
```yaml
47+
I pick {if({5050:.}!=):heads|tails}
48+
# 50% chance: I pick heads
49+
# 50% chance: I pick tails
50+
```
51+
52+
```yaml
53+
{?:Rare event occurred!} Welcome to the server!
54+
# 50% chance: Rare event occurred! Welcome to the server!
55+
# 50% chance: Welcome to the server!
56+
```
57+
58+
### Aliases
59+
60+
`5050`, `50`, `?`
61+
62+
</Callout>

apps/website/content/docs/tagscript/parsers/index.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ Parsers are used to parse a tag and return a value based on the tag. You can use
2828
Following is the list of builtin parsers:
2929

3030
- [BreakParser](/tagscript/parsers/break)
31+
- [FiftyFiftyParser](/tagscript/parsers/fifty-fifty)
3132
- [IfStatementParser](/tagscript/parsers/if-statement)
32-
- [UnionStatementParser](/tagscript/parsers/union-statement)
3333
- [IntersectionStatementParser](/tagscript/parsers/intersection-statement)
34+
- [RandomParser](/tagscript/parsers/random)
35+
- [RangeParser](/tagscript/parsers/range)
36+
- [ReplaceParser](/tagscript/parsers/replace)
37+
- [SliceParser](/tagscript/parsers/slice)
38+
- [StopParser](/tagscript/parsers/stop)
39+
- [UnionStatementParser](/tagscript/parsers/union-statement)
3440

3541
## Custom Parser
3642

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"break": "Break Parser",
3+
"fifty-fifty": "FiftyFifty Parser",
34
"if-statement": "If Statement Parser",
45
"intersection-statement": "Intersection Statement Parser",
6+
"random": "Random Parser",
7+
"range": "Range Parser",
8+
"replace": "Replace Parser",
9+
"slice": "Slice Parser",
10+
"stop": "Stop Parser",
511
"union-statement": "Union Statement Parser"
612
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: RandomParser
3+
---
4+
5+
import { Callout } from 'fumadocs-ui/components/callout';
6+
import { Tabs } from 'fumadocs-ui/components/tabs';
7+
8+
The random tag picks a random item from a list of strings, split by either `~` or `,`.
9+
This parser is useful for selecting random messages, responses, or values from a predefined list.
10+
11+
## Usage
12+
13+
<Tabs items={['ESM', 'CommonJs']}>
14+
```ts showLineNumbers tab="ESM"
15+
import { Interpreter, RandomParser } from 'tagscript';
16+
const ts = new Interpreter(new RandomParser());
17+
```
18+
```js showLineNumbers tab="CommonJs"
19+
const { Interpreter, RandomParser } = require('tagscript');
20+
const ts = new Interpreter(new RandomParser());
21+
```
22+
</Tabs>
23+
24+
## API
25+
26+
Check [RandomParser](../../typedoc-api/tagscript/classes/RandomParser) for the API documentation.
27+
28+
## For End Users
29+
30+
<Callout type="info" emoji={null}>
31+
### Syntax
32+
```yaml
33+
{random:item1,item2,item3}
34+
{random:item1~item2~item3}
35+
```
36+
37+
### Examples
38+
39+
```yaml
40+
{random:foo, bar, baz}
41+
# foo
42+
# bar
43+
# baz
44+
```
45+
46+
```yaml
47+
{random:Hello, Hi, Hey} there!
48+
# Hello there!
49+
# Hi there!
50+
# Hey there!
51+
```
52+
53+
```yaml
54+
{random:apple~banana~cherry~date}
55+
# apple
56+
# banana
57+
# cherry
58+
# date
59+
```
60+
61+
### Aliases
62+
63+
`rand`
64+
65+
</Callout>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: RangeParser
3+
---
4+
5+
import { Callout } from 'fumadocs-ui/components/callout';
6+
import { Tabs } from 'fumadocs-ui/components/tabs';
7+
8+
The range tag picks a random number from a range of numbers separated by `-` or `,`.
9+
The number range is inclusive, so it can pick the starting/ending number as well.
10+
Using the `rangef` tag will pick a number to the tenth decimal place for floating-point values.
11+
12+
## Usage
13+
14+
<Tabs items={['ESM', 'CommonJs']}>
15+
```ts showLineNumbers tab="ESM"
16+
import { Interpreter, RangeParser } from 'tagscript';
17+
const ts = new Interpreter(new RangeParser());
18+
```
19+
```js showLineNumbers tab="CommonJs"
20+
const { Interpreter, RangeParser } = require('tagscript');
21+
const ts = new Interpreter(new RangeParser());
22+
```
23+
</Tabs>
24+
25+
## API
26+
27+
Check [RangeParser](../../typedoc-api/tagscript/classes/RangeParser) for the API documentation.
28+
29+
## For End Users
30+
31+
<Callout type="info" emoji={null}>
32+
### Syntax
33+
```yaml
34+
{range:min-max}
35+
{range:min,max}
36+
{rangef:min-max}
37+
{rangef:min,max}
38+
```
39+
40+
### Examples
41+
42+
```yaml
43+
{range:1-10}
44+
# 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10
45+
```
46+
47+
```yaml
48+
Your lucky number is {range:10-30}!
49+
# Your lucky number is 14!
50+
# Your lucky number is 25!
51+
```
52+
53+
```yaml
54+
{rangef:5.0-7.0}
55+
I am guessing your height is {rangef:5-7}ft.
56+
# I am guessing your height is 5.3ft.
57+
# I am guessing your height is 6.8ft.
58+
```
59+
60+
```yaml
61+
Dice roll: {range:1,6}
62+
# Dice roll: 4
63+
```
64+
65+
### Aliases
66+
67+
`rangef` (for floating-point numbers)
68+
69+
</Callout>

0 commit comments

Comments
 (0)