Skip to content

Commit

Permalink
Added more lolicode docs and reformatted old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Jun 2, 2024
1 parent 135f0fb commit 0f4488b
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 58 deletions.
64 changes: 44 additions & 20 deletions docs/lolicode/blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,64 @@ sidebar_position: 2
---

# Syntax of blocks in LoliCode
Optional elements are enclosed in square brackets.
Blocks in LoliCode are the building blocks of a config. They are the smallest unit of work that can be done by the bot. They can be used to perform a wide variety of tasks, from simple arithmetic operations to complex HTTP requests.

Their syntax is as follows (optional elements are enclosed in square brackets):
```
BLOCK:Id
[LABEL:Custom label]
[DISABLED]
[SAFE]
[settingName = settingValue]
[=> VAR/CAP @outputVariable]
ENDBLOCK
```
- `Id`: the unique identifier of the block
- `settingName`: the unique name of a given setting of the block
- `settingValue`: see below
- `=> VAR/CAP @outputVariable`: if the block returns a value, you can define if it needs to be
a normal variable (`VAR`) or also marked as capture (`CAP`)

A block must start with the `BLOCK` keyword, followed by the block's unique identifier. The block ends with the `ENDBLOCK` keyword.

| Keyword | Description |
| ------- | ----------- |
| `BLOCK` | The start of a block |
| `Id` | The unique identifier of the block |
| `LABEL:Custom label` | A custom name for the block, will be shown in Stacker and in the bot log |
| `DISABLED` | If present, the block will be disabled and not executed |
| `SAFE` | If present, the block will be executed in safe mode. Any exceptions will be caught and the error message will be stored in the `data.ERROR` variable (not all blocks support this) |
| `settingName` | The unique name of a given setting of the block |
| `settingValue` | see below |
| `=> VAR/CAP @outputVariable` | The return value of the block, if any. You can define if it needs to be a normal variable (`VAR`) or also marked as capture (`CAP`) |
| `ENDBLOCK` | The end of a block |

## Setting values
Setting values can have 3 types:
- Fixed (e.g. `"hello"` or `123`)
- Interpolated (e.g. `$"My name is <name>"`)
- Variable (e.g. `@name`)
- Fixed (e.g., `"hello"` or `123`)
- Interpolated (e.g., `$"My name is <name>"`)
- Variable (e.g., `@name`)

### Fixed value types
- Bool (`true` or `false`)
- Int (e.g. `123`)
- Float (e.g. `0.42`)
- String (e.g. `"hello"`)
- Byte Array (as base64 e.g. `plvB6Yer`)
- List of Strings (e.g. `["one", "two", "three"]`)
- Dictionary of Strings (e.g. `{("one", "first"), ("two", "second"), ("three", "third")}`)
Fixed values are constants that are defined in the config. They can be of the following types:

| Type | Example |
| ---- | ------- |
| Bool | `true` or `false` |
| Int | `123` |
| Float | `0.42` |
| String | `"hello"` |
| Enum | Depends on the setting, e.g., `GET` for the Method setting of a Request block |
| Byte Array | `plvB6Yer` |
| List of Strings | `["one", "two", "three"]` |
| Dictionary of Strings | `{("one", "first"), ("two", "second"), ("three", "third")}` |

### Interpolated value types
- String (e.g. `$"This is my <name>"`)
- List of Strings (e.g. `$["one", "<secondNumber>", "three"]`)
- Dictionary of Strings (e.g. `${("one", "first"), ("<secondNumber>", "second"), ("three", "third")}`)
Interpolated values are strings that can contain variables. They can be of the following types:

| Type | Example |
| ---- | ------- |
| String | `$"This is my <name>"` |
| List of Strings | `$["one", "<secondNumber>", "three"]` |
| Dictionary of Strings | `${("one", "first"), ("<secondNumber>", "second"), ("three", "third")}` |

### Variable value types
Variable values are references to variables that are defined in the config.

## Final notes
- There is automatic type casting, so you can use a variable of type `Int` in a setting of type `String`
- There is automatic type casting, which means, for example, that you can use a variable of type `Int` in a setting of type `String`
86 changes: 51 additions & 35 deletions docs/lolicode/bot_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,64 @@ sidebar_position: 3
This variable contains all data related to the current bot.

## Useful properties
- `data.UseProxy` (`bool`) whether to use the proxy assigned to the bot
- `data.STATUS` (`string`) the current status of the bot
- `data.RAWSOURCE` (`byte[]`) the content of the last http response received
- `data.SOURCE` (`string`) same as above but as a string
- `data.ERROR` (`string`) contains the message of the last exception caught when using safe mode (in blocks that support it)
- `data.ADDRESS` (`string`) the absolute uri of the last http response (after redirection)
- `data.RESPONSECODE` (`int`) the status code of the last http response
- `data.COOKIES` (`Dictionary<string, string>`) the cookies sent or received so far (e.g. `data.COOKIES["PHPSESSID"]`)
- `data.HEADERS` (`Dictionary<string, string>`) the headers of the last http response (e.g. `data.HEADERS["Location"]`)
- `data.Objects` (`Dictionary<string, object>`) holds stateful objects for cross-block use (they will get disposed automatically at the end of the script)
- `data.MarkedForCapture` (`List<string>`) all the names of variables marked for capture
- `data.CaptchaCredit` the captcha credits that are left
- `data.BOTNUM` the number of the bot (0 for debugger, 1... for bots in a multi run job)
| Property | Type | Description |
| -------- | ---- | ----------- |
| `data.UseProxy` | `bool` | Whether to use the proxy assigned to the bot |
| `data.STATUS` | `string` | The current status of the bot |
| `data.RAWSOURCE` | `byte[]` | The content of the last http response received |
| `data.SOURCE` | `string` | Same as above but as a string |
| `data.ERROR` | `string` | Contains the message of the last exception caught when using safe mode (in blocks that support it) |
| `data.ADDRESS` | `string` | The absolute uri of the last http response (after redirection) |
| `data.RESPONSECODE` | `int` | The status code of the last http response |
| `data.COOKIES` | `Dictionary<string, string>` | The cookies sent or received so far (e.g. `data.COOKIES["PHPSESSID"]`) |
| `data.HEADERS` | `Dictionary<string, string>` | The headers of the last http response (e.g. `data.HEADERS["Location"]`) |
| `data.Objects` | `Dictionary<string, object>` | Holds stateful objects for cross-block use (they will get disposed automatically at the end of the script) |
| `data.MarkedForCapture` | `List<string>` | All the names of variables marked for capture |
| `data.CaptchaCredit` | `decimal` | The captcha credits that are left |
| `data.BOTNUM` | `int` | The number of the bot (0 for debugger, 1... for bots in a multi run job) |

### Line
- `data.Line.Data` (`string`) the whole (unsplit) data line assigned to the bot
- `data.Line.Retries` (`int`) the amount of times the data has been retried
| Property | Type | Description |
| -------- | ---- | ----------- |
| `data.Line.Data` | `string` | The whole (unsplit) data line assigned to the bot |
| `data.Line.Retries` | `int` | The amount of times the data has been retried |

### Proxy
Note: `data.Proxy` is null if proxies are off, so always make a null check first
- `data.Proxy.Host` (`string`)
- `data.Proxy.Port` (`int`)
- `data.Proxy.Username` (`string`)
- `data.Proxy.Password` (`string`)
- `data.Proxy.Type` (`ProxyType`) can be `Http`/`Socks4`/`Socks5`/`Socks4a`
- ... and more! Check out [this page](../proxies/proxies-for-config-makers.md) for more information
| Property | Type | Description |
| -------- | ---- | ----------- |
| `data.Proxy.Host` | `string` | The host of the proxy |
| `data.Proxy.Port` | `int` | The port of the proxy |
| `data.Proxy.Username` | `string` | The username of the proxy |
| `data.Proxy.Password` | `string` | The password of the proxy |
| `data.Proxy.Type` | `ProxyType` | The type of the proxy, can be `Http`/`Socks4`/`Socks5`/`Socks4a` |

... and more! Check out [this page](../proxies/proxies-for-config-makers.md) for more information on the `Proxy` object.

:::warning WARNING
`data.Proxy` is null if proxies are off, so always remember to make a null check first!
:::

### Logger
- `data.Logger.Enabled` (`bool`) enables or disables the logger (e.g. when there is too much data to print)
| Property | Type | Description |
| -------- | ---- | ----------- |
| `data.Logger.Enabled` | `bool` | Enables or disables the logger (e.g. when there is too much data to print) |

## Useful methods
- `data.MarkForCapture(string varName)` adds the variable name to the `data.MarkedForCapture` list
- `data.Logger.Log(string message, string htmlColor, bool canViewAsHtml)` htmlColor must be e.g. `#fff` or `white`
- `data.Logger.LogObject(object obj, string htmlColor, bool canViewAsHtml)`
- `data.Logger.Log(IEnumerable<string> enumerable, string htmlColor, bool canViewAsHtml)`
- `data.Logger.Clear()` clears the log
| Method | Description |
| ------ | ----------- |
| `data.MarkForCapture(string varName)` | Adds the variable name to the `data.MarkedForCapture` list |
| `data.Logger.Log(string message, string htmlColor, bool canViewAsHtml)` | Logs a message with the specified color, `htmlColor` must be e.g. `#fff` or `white` |
| `data.Logger.LogObject(object obj, string htmlColor, bool canViewAsHtml)` | Logs an object with the specified color |
| `data.Logger.Log(IEnumerable<string> enumerable, string htmlColor, bool canViewAsHtml)` | Logs a list of strings with the specified color |
| `data.Logger.Clear()` | Clears the log |

## Other properties
- `data.ConfigSettings` to access the config settings object
- `data.Providers` to access providers for captchas, browsers etc. (usually what you can configure in RL settings)
- `data.Random` shared instance of a random number generator, use this to prevent bots from getting the same random values
- `data.CancellationToken` will be cancelled when a user stops the debugger or the job, useful if you want to call async methods
- `data.AsyncLocker` async locker for multi-thread operations
- `data.Stepper` the class that handles step-by-step debugging
- `data.ExecutionInfo` the current execution info, displayed in the detailed bots view of a multi run job
| Property | Type | Description |
| -------- | ---- | ----------- |
| `data.ConfigSettings` | `ConfigSettings` | The config settings object |
| `data.Providers` | `Providers` | Providers for captchas, browsers etc. (usually what you can configure in RL settings) |
| `data.Random` | `Random` | Shared instance of a random number generator, use this to prevent bots from getting the same random values |
| `data.CancellationToken` | `CancellationToken` | Will be cancelled when a user stops the debugger or the job, useful if you want to call async methods |
| `data.AsyncLocker` | `AsyncLocker` | Async locker for multi-thread operations |
| `data.Stepper` | `Stepper` | The class that handles step-by-step debugging |
| `data.ExecutionInfo` | `string` | The current execution info, displayed in the detailed bots view of a multi run job |
29 changes: 28 additions & 1 deletion docs/lolicode/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,31 @@ sidebar_position: 5
---

# The `globals` variable
*Coming soon...*
The `globals` variable contains data shared across all bots in a multi-run job. It can be used to store data that needs to be shared between bots, such as authentication tokens, counters, or other shared state.

:::info NOTE
The `globals` variable is the only one that is available in the [startup script](../lolicode/startup_script.md)'s code. This allows you to set up shared resources and state before the bots start running.
:::


## Under the hood
The `globals` variable is declared as a `dynamic` C# object. This means that you can store any type of data in it, and access it using the same syntax as you would in C#. `dynamic` is backed by the `ExpandoObject` class, which allows you to add and remove properties at runtime.

For example, you can store a value in the `globals` variable like this:
```csharp
globals.myValue = 42;
```

And then access it like this:
```csharp
int value = globals.myValue;
```

## Predefined properties
Some properties are predefined in the `globals` variable. These properties are used by the system and should not be modified by the user, but they can be read to get information about the current job.

| Property | Type | Description |
| -------- | ---- | ----------- |
| `globals.JobId` | `int` | The ID of the current job (0 in case of the debugger). |
| `globals.Resources` | `Dictionary<string, ConfigResource>` | A dictionary of resources shared across all bots in the job. Resources can be configured in the Config Settings > Data > Resources tab. |
| `globals.OwnerId` | `int` | The ID of the user who created the job. The admin user has id 0, while guest users have their own unique IDs. |
18 changes: 17 additions & 1 deletion docs/lolicode/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ sidebar_position: 7
---

# The `input` variable
*Coming soon...*
Bots have access to the `input` variable, which contains the data line that is being processed by the bot, and any custom input that was configured in the config settings.

## Data line
Each data line is sliced into variables that can be accessed by the bot. The variables are named according to the `Slices` field of the wordlist type in the `Environment.ini` file. Read more about how this process works [here](../wordlists/general-info.md). These variables (e.g., `input.DATA` or `input.USERNAME`) are always of type `string`.

## Custom inputs
Custom inputs are defined in the config settings and can be used to provide additional data to the bot. For example, you could define a custom input called `apiKey` and assign it a value. The bot can then access this value using `input.apiKey`. When a user runs a multi run job, they can configure the values of the custom inputs to be used. This allows you to run the same config with different input values. These variables are also always of type `string`.

You can define custom inputs in the Config Settings > Data > Inputs section.

![Custom Inputs](/img/lolicode/custom_inputs.png)

When you run a multi run job, you can configure the values of the custom inputs to be used directly in the job's page.

![Custom Inputs in a job](/img/lolicode/custom_inputs_job.png)

In the debugger, the values used will be the default ones defined in the config settings.
14 changes: 13 additions & 1 deletion docs/lolicode/startup_script.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ sidebar_position: 6
---

# Startup script
*Coming soon...*
The startup script is a special script that runs before the main script starts. It is used to set up shared resources and state that need to be shared between bots in a multi-run job.

The only variable available in the startup script is `globals`. You can read more about the `globals` variable [here](../lolicode/globals.md).

:::warning WARNING
You do not have access to the `data` or `input` variables in the startup script, as they are only available in the main script, since they are specific to each bot.
:::

In the startup script, you can use regular LoliCode and C# code to set up shared resources and state. For example, you can use an `HttpRequest` block to retrieve a login cookie and save it to the `globals` variable. Then, in the main script, you can use the cookie to authenticate the bots.

The startup script can be toggled on or off through a button just above the main script. If you turn it off, the main script will start running immediately without executing the startup script.

![Startup script](/img/lolicode/startup_script.png)
1 change: 1 addition & 0 deletions docs/lolicode/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sidebar_position: 4
---

# LoliCode statements
In addition to blocks, LoliCode also has statements that can be used to control the flow of the script, print messages to the debugger log, and more.

## LOG
Prints text to the debugger log.
Expand Down
24 changes: 24 additions & 0 deletions docs/lolicode/usings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
sidebar_label: 'Usings'
sidebar_position: 8
---

# Using statements
Sometimes, you may want to use external libraries or namespaces in your LoliCode script. You can do this by adding `using` statements in the appropriate section. Using statements need to be defined one per line, with just the namespace name.

For example, if you try to use the `Regex` class from the `System.Text.RegularExpressions` namespace:

```loli
string match = new Regex(@"^\d{4}").Match(input.DATA).ToString();
CLOG Magenta @match
```

You will get an error message like this:

```
[IDLE] CompilationErrorException: (3,20): error CS0246: The type or namespace name 'Regex' could not be found (are you missing a using directive or an assembly reference?)
```

If instead you add the `using` statement, you will be able to use the `Regex` class successfully.

![Using statements](/img/lolicode/usings.png)
Binary file added static/img/lolicode/custom_inputs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/lolicode/custom_inputs_job.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/lolicode/startup_script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/lolicode/usings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f4488b

Please sign in to comment.