Skip to content

Commit

Permalink
Added LoliCode documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Jun 1, 2024
1 parent 1a8feff commit 135f0fb
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 6 deletions.
1 change: 0 additions & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ The following features are **not supported**:
- selenium chrome extensions
- random UA for selenium
- step by step debugging (issue already on github)
- the *BOTNUM* variable
- OB1 block plugins
2 changes: 1 addition & 1 deletion docs/jobs/job-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 2
# Job Monitor
The *job monitor* allows you to monitor your jobs and execute some actions if they meet specific conditions. Each set of conditions and actions to execute is called a *triggered action*.

### Triggered action
### Triggered actions
A *triggered action* is made of *triggers* and *actions*. When **all** triggers in a triggered action are satisfied **at the same time**, the triggered action will execute **all** the actions, **in sequence** (one after the other).

For example, you might want to create a triggered action that stops a job after it gets a single hit. Here's how you would set it up:
Expand Down
4 changes: 4 additions & 0 deletions docs/lolicode/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "LoliCode",
"position": 11
}
43 changes: 43 additions & 0 deletions docs/lolicode/blocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
sidebar_label: 'Blocks'
sidebar_position: 2
---

# Syntax of blocks in LoliCode
Optional elements are enclosed in square brackets.
```
BLOCK:Id
[LABEL:Custom label]
[DISABLED]
[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`)

## 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 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")}`)

### 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")}`)

## Final notes
- There is automatic type casting, so you can use a variable of type `Int` in a setting of type `String`
54 changes: 54 additions & 0 deletions docs/lolicode/bot_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
sidebar_label: 'Bot data'
sidebar_position: 3
---

# The `data` variable
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)

### 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

### 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

### Logger
- `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

## 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
45 changes: 45 additions & 0 deletions docs/lolicode/general-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
sidebar_label: 'General info'
sidebar_position: 1
---

# LoliCode
*LoliCode* is the custom scripting language of OpenBullet 2.

:::info INFO
*LoliCode* should not be confused with *LoliScript*, the scripting language of the previous version of OpenBullet.
:::

*LoliCode* is the language in which blocks are actually saved when you edit them in Stacker. It compiles to C# code when it is executed by a bot, and it can be mixed with valid C# code to produce complex logic and expand the features of OpenBullet 2 with just a bit of programming knowledge.

This is an example of *LoliCode* mixed with C# code
```loli
// You can define C# methods like this
int Add(int first, int second)
{
return first + second;
}
// This is the representation of a block you see in Stacker
BLOCK:RandomInteger
minimum = 0
maximum = 10
=> VAR @num1
ENDBLOCK
BLOCK:RandomInteger
minimum = 0
maximum = 10
=> VAR @num2
ENDBLOCK
// A piece of pure C# code
int result = Add(num1, num2);
// These are LoliCode statements. You can also use plain C#
IF INTKEY @result GreaterThan 10
CLOG DarkCyan $"Result: {result}"
ELSE
CLOG Cyan $"Result: {result}"
END
```
7 changes: 7 additions & 0 deletions docs/lolicode/globals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_label: 'Globals'
sidebar_position: 5
---

# The `globals` variable
*Coming soon...*
7 changes: 7 additions & 0 deletions docs/lolicode/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_label: 'Input'
sidebar_position: 7
---

# The `input` variable
*Coming soon...*
7 changes: 7 additions & 0 deletions docs/lolicode/startup_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_label: 'Startup script'
sidebar_position: 6
---

# Startup script
*Coming soon...*
178 changes: 178 additions & 0 deletions docs/lolicode/statements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---
sidebar_label: 'Statements'
sidebar_position: 4
---

# LoliCode statements

## LOG
Prints text to the debugger log.
Example:
```
LOG "hello"
```
---
## CLOG
Prints colored text to the debugger log.
A full list of colors is available [here](https://www.colorhexa.com/color-names) (remove dashes and spaces and apply PascalCase).
Example:
```
CLOG YellowGreen "hello"
```
---
## JUMP
Jumps to a specified point in the code. Remember to watch out for endless loops!
Example:
```
...
#HERE
...
JUMP #HERE
```
---
## REPEAT
Repeats something N times.
Example:
```
REPEAT 5
LOG "hello"
END
```
---
## FOREACH
Iterates on a list variable.
Example:
```
BLOCK:ConstantList
value = ["one", "two", "three"]
=> VAR @list
ENDBLOCK
FOREACH elem IN list
LOG elem
END
```
---
## WHILE
Executes something while a condition is true.
Example:
```
WHILE INTKEY 1 LessThan 2
...
END
```
---
## IF / ELSE / ELSE IF
Executes something, or something else.
Example:
```
IF INTKEY 5 LessThan 1
LOG "nope"
ELSE IF INTKEY 5 LessThan 3
LOG "nope again"
ELSE
LOG "yep"
END
```
---
## TRY / CATCH
Executes something. If it fails, executes something else.
Example:
```
TRY
// request to an unreliable URL
CATCH
// fallback request to a reliable URL
END
```
---
## LOCK
Very useful if you want to execute synchronous operations on global variables.
It makes sure that only 1 bot can enter a given piece of code at a time, so that multiple bots do not edit the same global variable at the same time.
Often used in conjunction with TRY/CATCH.
Example:
```
LOCK globals
TRY
// Try to increase globals.Count by 1 if it exists
globals.Count++;
CATCH
// Create globals.Count if it doesn't exist
globals.Count = 1;
END
END
```
---
## ACQUIRELOCK / RELEASELOCK
Very useful if you want to execute asynchronous operations on global variables.
It makes sure that only 1 bot can enter a given piece of code at a time, so that multiple bots do not edit the same global variable at the same time.
You MUST use this in conjunction with TRY/CATCH/FINALLY.
Example:
```
ACQUIRELOCK globals
TRY
// Do some async operation here
CATCH
throw; // Rethrow any exception
FINALLY
RELEASELOCK globals
END
```
---
## SET VAR/CAP
Sets a string variable, and optionally also marks it for capture. Introduced for consistency with OB1.
Example:
```
SET VAR @myString "variable"
LOG myString
SET CAP @myCapture "capture"
LOG myCapture
```
---
## SET USEPROXY
Sets whether to use the currently set proxy or not.
Example:
```
SET USEPROXY TRUE
SET USEPROXY FALSE
```
---
## SET PROXY
Sets a given proxy. The available types are: HTTP, SOCKS4, SOCKS4A, SOCKS5.
Example:
```
SET PROXY "127.0.0.1" 9050 SOCKS5
SET PROXY "127.0.0.1" 9050 SOCKS5 "username" "password"
```
---
## MARK
Adds a variable to the capture.
Example:
```
MARK @myVar
```
---
## UNMARK
Removes a variable from the capture.
Example:
```
UNMARK @myVar
```
---
## TAKEONE
Takes a single item from a resource. You can configure resources in Config Settings > Data > Resources.
You need to provide the name of the resource and the name of the variable that will be created (of type `string`).
Example:
```
TAKEONE FROM "resourceName" => @myString
LOG myString
```
---
## TAKE
Takes a multiple items from a resource. You can configure resources in Config Settings > Data > Resources.
You need to provide the name of the resource and the name of the variable that will be created (of type `List<string>`).
Example:
```
TAKE 5 FROM "resourceName" => @myList
```
4 changes: 0 additions & 4 deletions docs/modding/_category_.json

This file was deleted.

4 changes: 4 additions & 0 deletions docs/plugins/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Plugins",
"position": 10
}
9 changes: 9 additions & 0 deletions docs/plugins/general-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sidebar_label: 'General Info'
sidebar_position: 1
---

# Plugins
Plugins allow you to expand the functionalities of OpenBullet 2 by adding your own custom blocks to use in a Config.

*More coming soon...*

0 comments on commit 135f0fb

Please sign in to comment.