LoliCode language documentation

Introduction

This is a collection of all the LoliCode-related documentation that can also be found inside the official OpenBullet 2 webapp as shown in the image.

immagine

Refer to this topic for any concern regarding the syntax of LoliCode, the available variables and the available syntax sugar for C# directives.

Blocks

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

Variables

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

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

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.Log(IEnumerable<string> enumerable, string htmlColor, bool canViewAsHtml)
  • data.Logger.Clear() clears the log

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 (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 Likes