Wiki

Lua coding

As of version 1.1, ilotterytea’s twitch bot allows you to run custom scripts written in Lua in Twitch chats. The scripts are run in the Luau sandbox (in simpler terms, Roblox’s Lua). This is a safe environment that prevents malicious code from doing its bad things by removing access to certain libraries.

Also, there are execution limits for scripts - 2MB RAM and 500 milliseconds wait time. These limits are made for cases where you may have forgotten "while-true loop" and so it doesn’t run indefinitely until the bot shuts down, the loop will stop after 500 milliseconds. Additionally, it’s a test to see if you know how to write optimized code :)

The bot provides API calls for your scripts, which will be expanded in the future, and commands that allow you to run Lua scripts.

If you are interested in any examples, there are a mini-game about drinking ’not milk’ and internal Lua commands.

Have fun!

Commands

Syntax

Lua script in chat

!lua <code...>

  • <code> - Lua-validated code.

Remote Lua script

!luaimport <provider>:<id>

  • <provider> - A paste-like service. Available services: pastebin (Pastebin), pastea (Rustpastes).
  • <id> - An ID of the paste.

Usage

  • !lua 2+2
  • !lua function hello(name) return "hello, " .. name end return hello("chat")
  • !luaimport pastebin:Ejdrqmb7

Responses

  • 🌑 4
  • 🌑 hello, chat
  • 🌑 hello ilotterytea! you just ran a remote script

Error handling

List of API calls

Localization

  • l10n_formatted_text_request(request, line_id, parameters) -> String - Get translated, formatted text.

Time

  • time_current() -> Integer - Get current UTC time in milliseconds.
  • time_humanize(timestamp) -> String - Convert UNIX timestamp to humanized timestamp (e.g. 5m10s, 25y09mo)

Storage (!luaimport only)

  • storage_get() -> String - Get user’s storage cell. Returns an empty string if it was just created.
  • storage_put(string) -> Bool - Put string to user’s storage cell. Returns true if it was successful.
  • storage_channel_get() -> String - Get channel’s storage cell. Returns an empty string if it was just created.
  • storage_channel_put(string) -> Bool - Put string to channel’s storage cell. Returns true if it was successful.

JSON

  • json_parse(string) -> Table - Convert stringified JSON to valid Lua value.
  • json_stringify(Any) -> String - Convert Lua value to stringified JSON

Bot

  • bot_get_compiler_version() -> String - Get Rust compiler version.
  • bot_get_uptime() -> Integer - Get bot uptime in milliseconds.
  • bot_get_memory_usage() -> Integer - Get current memory usage in bytes.
  • bot_get_compile_time() -> Integer - Get compilation timestamp in seconds.
  • bot_get_version() -> String - Get bot version.

List of structs

Request

Request {
    command_id: String,
    subcommand_id: String | Nil,
    message: String | Nil,
    sender: Sender {
        id: Integer,
        alias_id: Integer,
        alias_name: String,
        joined_at: Integer,
        opted_out_at: Integer | Nil
    },
    channel: Channel {
        id: Integer,
        alias_id: Integer,
        alias_name: String,
        joined_at: Integer,
        opted_out_at: Integer | Nil
    },
    channel_preference: ChannelPreference {
        id: Integer,
        channel_id: Integer,
        prefix: String,
        language: String,
        features: (String | Nil)[]
    },
    rights: Rights {
        id: Integer,
        user_id: Integer,
        channel_id: Integer,
        level: String,
        is_fixed: Bool
    }
}

Powered by ilotterytea.