Skip to content

Library of helpful STScript commands for SillyTavern.

Notifications You must be signed in to change notification settings

statchamber/SillyTavern-LALib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LALib

Library of STScript commands.

  • Boolean Operations (test, and, or, not)
  • List Operations (foreach, map, filter, find, slice, shuffle, dict)
  • Split & Join (split, join)
  • Text Operations (trim, replace, replaceAll, diff, json-pretty)
  • Accessing & Manipulating Structured Data (getat, setat)
  • Exception Handling (try, catch)
  • Copy & Download (copy, download)
  • DOM Interaction (dom)
  • Group Chats (memberpos)
  • Conditionals - switch (switch, case)
  • Conditionals - if (ife, elseif, else, then)
  • World Info (wi-list-books, wi-list-entries)
  • Costumes / Sprites (costumes)
  • Quick Replies (qr-edit, qr-add)
  • Chat Messages (swipes-get, swipes-list, swipes-count, swipes-index, swipes-add, swipes-del, swipes-go, swipes-swipe, message-edit)
  • Time & Date (timestamp)
  • Async (fireandforget)

Requirements

Commands

Help

/lalib?

Lists LALib commands

Examples
/lalib?

Boolean Operations

/test

left=val rule=rule right=val

Returns true or false, depending on whether left and right adhere to rule. Available rules: gt => a > b, gte => a >= b, lt => a < b, lte => a <= b, eq => a == b, neq => a != b, not => !a, in (strings) => a includes b, nin (strings) => a not includes b

Examples
/setvar key=x 1 |
/setvar key=y 2 |
/test left={{getvar::x}} rule=eq right={{getvar::y}} |
/echo The result will be "false": {{pipe}}
/setvar key=x 1 |
/setvar key=y 2 |
/test left={{getvar::x}} rule=lt right={{getvar::y}} |
/echo The result will be "true": {{pipe}}

/and

left=val right=val

Returns true if both left and right are true, otherwise false.

Examples
/and left=true right=false |
/echo The result will be "false": {{pipe}}
/and left=true right=true |
/echo The result will be "true": {{pipe}}

/or

left=val right=val

Returns true if at least one of left and right are true, false if both are false.

Examples
/or left=true right=false |
/echo The result will be "true": {{pipe}}
/or left=false right=false |
/echo The result will be "false": {{pipe}}

/not

(value)

Returns true if value is false, otherwise true.

Examples
/not true |
/echo The result will be "false": {{pipe}}
/not false |
/echo The result will be "true": {{pipe}}

List Operations

/foreach

[optional list=[1,2,3]] [optional var=varname] [optional globalvar=globalvarname] (/command {{item}} {{index}})

Executes command for each item of a list or dictionary.

Examples
/setvar key=x ["A", "B", "C"] |
/foreach var=x
    /echo Item {{index}} is {{item}} \|
    /delay 400
/foreach list={"a":"foo","b":"bar"}
    /echo Item {{index}} is {{item}} \|
    /delay 400

/map

[optional list=[1,2,3]] [optional var=varname] [optional globalvar=globalvarname] (/command {{item}} {{index}})

Executes command for each item of a list or dictionary and returns the list or dictionary of the command results.

Examples
/setvar key=x [1,2,3] |
/map var=x
    /mul {{item}} {{item}}
|
/echo Squares: {{pipe}}
/map list={"a":"foo","b":"bar"}
    /return This is item {{index}} with value {{item}}
|
/echo

/filter

[optional list=[1,2,3]] [optional var=varname] [optional globalvar=globalvarname] (/command {{item}} {{index}})

Executes command for each item of a list or dictionary and returns the list or dictionary of only those items where the command returned true.

Examples
/setvar key=x [1,2,3,4,5,6,7,8,9,10] |
/filter var=x
    /mod {{item}} 2 \|
    /test left=\{\{pipe\}\} rule=eq right=0
|
/echo Only even numbers: {{pipe}}
/filter list={"a":"foo","b":"bar"}
    /test left={{item}} rule=in right=a
|
/echo Only items that include an "a": {{pipe}}

/find

[optional list=[1,2,3]] [optional var=varname] [optional globalvar=globalvarname] (/command {{item}} {{index}})

Executes command for each item of a list or dictionary and returns the first item where the command returned true.

Examples
/setvar key=x [2,4,6,8,10] |
/find var=x
    /test left={{item}} rule=gt right=5
|
/echo The first item greater than 5: {{pipe}}
/find list={"a":"foo","b":"bar","c":"foobar","d":"barfoo"}
    /len {{item}} \|
    /test left=\{\{pipe\}\} rule=gt right=3
|
/echo The first item longer than 3 characters: {{pipe}}

/slice

start=int [optional end=int] [optional length=int] [optional var=varname] [optional globalvar=globalvarname] (optional value)

Retrieves a slice of a list or string.

Examples
/setvar key=x [1,2,3,4,5] |
/slice var=x start=2 |
/echo The result will be "[3,4,5]": {{pipe}}
/slice start=-3 foo bar |
/echo The result will be "bar": {{pipe}}

/shuffle

(list to shuffle)

Returns a shuffled list.

Examples
/shuffle [1,2,3,4,5] |
/echo

/dict

[optional var=varname] [optional globalvar=globalvarname] (list of lists)

Takes a list of lists (each item must be a list of at least two items) and creates a dictionary by using each items first item as key and each items second item as value.

Examples
/setvar key=x [
    ["a", 1],
    ["b", 2],
    ["c", 3]
] |
/dict var=x |
/echo

Split & Join

/split

[optional find=","] [optional trim=true|false] [optional var=varname] [optional globalvar=globalvarname] (value)

Splits value into list at every occurrence of find. Supports regex find=/\s/

Examples
/split foo, bar |
/echo The result will be ["foo", "bar"]: {{pipe}}
/split find=/o.+?o/g The quick brown fox jumps over the lazy dog. |
/echo The result will be ["The quick br", "x jumps", "g."]: {{pipe}}

/join

[optional glue=", "] [optional var=varname] [optional globalvar=globalvarname] (optional list)

Joins the items of a list with glue into a single string. Use glue={{space}} to join with a space.

Examples
/setvar key=x ["a","b","c"] |
/join var=x |
/echo The result will be "a, b, c": {{pipe}}
/join glue=::: ["foo", "bar"] |
/echo The result will be "foo:::bar": {{pipe}}

Text Operations

/trim

(text to trim)

Removes whitespace at the start and end of the text.

Examples
/return [" foo", "bar "] |
/getat index=0 |
/trim |
/echo

/replace

[find=string_or_regex] [replace=string] [optional var=varname] [optional globalvar=globalvarname] (optional value)

Replaces the first occurrence of "find" with "replace" in the given value or variable.

Examples
/replace find="cat" replace="dog" The cat sat on the mat |
/echo The result will be "The dog sat on the mat": {{pipe}}
/setvar key=sentence There are 123 apples |
/replace find="/\d+/" replace="NUMBER" var=sentence |
/echo The result will be "There are NUMBER apples": {{pipe}}

/replaceAll

[find=string_or_regex] [replace=string] [optional var=varname] [optional globalvar=globalvarname] (optional value)

Replaces all occurrences of "find" with "replace" in the given value or variable.

Examples
/replaceAll find="apple" replace="orange" I like apples and apple pie |
/echo The result will be "I like oranges and orange pie": {{pipe}}
/setvar key=sentence This is a test sentence |
/replaceAll find="/[aeiou]/g" replace="-" var=sentence |
/echo The result will be "Th-s -s - t-st s-nt-nc-": {{pipe}}

/diff

[optional all=true] [optional buttons=true] [optional stripcode=true] [optional notes=text] [old=oldText] [new=newText]

Compares old text vs new text and displays the difference between the two. Use all=true to show new, old, and diff side by side. Use buttons=true to add buttons to pick which text to return. Use stripcode=true to remove all codeblocks before diffing. Use notes="some text" to show additional notes or comments above the comparison.

Examples
/echo comparing the last two messages |

/sub {{lastMessageId}} 1 |
/messages names=off |
/split find=``` |
/getat index=-1 |
/let old {{pipe}} |
/setvar key=old {{var::old}} |

/messages names=off {{lastMessageId}} |
/split find=``` |
/getat index=-1 |
/let new {{pipe}} |
/setvar key=new {{var::new}} |

/diff old={{var::old}} new={{var::new}}
/diff old="The quick brown fox jumps over the lazy dog." new="The fast spotted fox jumps across the sleeping dog." notes="Foxes and dogs." all=true

/json-pretty

(JSON)

Pretty print JSON.

Examples
/json-pretty {"a":1, "b":[1,2,3]} |
/send ```json{{newline}}{{pipe}}{{newline}}```

Accessing & Manipulating Structured Data

/getat

index=int|fieldname|list [optional var=varname] [optional globalvar=globalvarname] (optional value)

Retrieves an item from a list or a property from a dictionary.

Examples
/setvar key=x {
    "a": [
        1,
        2,
        {
            "b": "foo",
            "c": "bar"
        }
    ],
    "d": "D"
} |
/getat var=x index=d |
/echo The result will be "D": {{pipe}}
/return {
    "a": [
        1,
        2,
        {
            "b": "foo",
            "c": "bar"
        }
    ],
    "d": "D"
} |
/getat index=["a", 2, "b"] |
/echo The result will be "foo": {{pipe}}
/return {
    "a": [
        1,
        2,
        {
            "b": "foo",
            "c": "bar"
        }
    ],
    "d": "D"
} |
/getat index=a |
/getat index=2 |
/getat index=c |
/echo The result will be "bar": {{pipe}}

/setat

index=int|fieldname|list [optional var=varname] [optional globalvar=globalvarname] [optional value=list|dictionary] (value)

Sets an item in a list or a property in a dictionary. Example: /setat value=[1,2,3] index=1 X returns [1,"X",3], /setat var=myVariable index=[1,2,"somePropery"] foobar sets the value of myVariable[1][2].someProperty to "foobar" (the variable will be updated and the resulting value of myVariable will be returned). Can be used to create structures that do not already exist.

Examples
/setvar key=x {
    "a": [
        1,
        2,
        {
            "b": "foo",
            "c": "bar"
        }
    ],
    "d": "D"
} |
/setat var=x index=d new value for D |
/echo {{getvar::x}}
/setvar key=x {
    "a": [
        1,
        2,
        {
            "b": "foo",
            "c": "bar"
        }
    ],
    "d": "D"
} |
/setat var=x index=["a", 2, "c"] new value for bar |
/echo {{getvar::x}}
/flushvar x |
/setat var=x index=["a","b",2] creating new objects or list |
/echo {{getvar::x}}

Exception Handling

/try

(command)

try catch.

Examples
/echo Try this first while being connected to an LLM, then without a connection. |
/setvar key=myPrompt Say hello! |
/try
	/getvar myPrompt \|
	/gen \{\{pipe}}
|
/catch pipe={{pipe}}
	/echo something went wrong: {{error}} \|
	/return "gen failed :("
|
/echo {{pipe}}

/catch

[pipe={{pipe}}] (command)

try catch. You must always set pipe={{pipe}} and /catch must always be called right after /try. Use {{exception}} or {{error}} to get the exception's message.

Examples
see /try

Copy & Download

/copy

(value)

Copies value into clipboard.

Examples
/copy this text is now in your clipboard
/copy {{lastMessage}}

/download

[optional name=filename] [optional ext=extension] (value)

Downloads value as a text file.

Examples
/download Let's download this text.
/download name=TheLastMessage ext=md {{lastMessage}}

DOM Interaction

/dom

[action=click|value|property] [optional value=newValue] [optional property=propertyName] [optional attribute=attributeName] (CSS selector)

Click on an element, change its value, retrieve a property, or retrieve an attribute. To select the targeted element, use CSS selectors. Example: /dom action=click #expandMessageActions or /dom action=value value=0 #avatar_style

Examples
/dom action=click #fast_ui_mode |
/echo Toggled "No Blur Effect" setting
/dom action=value value=0 #avatar_style |
/echo Avatar style has been set to "Circle"
/dom action=property property=value #avatar_style |
/echo Current avatar style: {{pipe}}
/dom action=attribute attribute=is_system #chat > .mes:last-child |
/echo Is the last message a system message? {{pipe}}

Group Chats

/memberpos

(name) (position)

Move group member to position (index starts with 0).

Examples
/memberpos Alice 3 |
/echo Alice has been moved to position 3

Conditionals - switch

/switch

[optional var=varname] [optional globalvar=globalvarname] (optional value)

Use with /case.

Examples
/setvar key=x foo |
/switch var=x |
    /case pipe={{pipe}} value=1 /echo value is one |
    /case pipe={{pipe}} value=foo /echo value is foo |
    /case pipe={{pipe}} value=bar /echo value is bar |
/echo done

/case

[pipe={{pipe}}] [value=comparisonValue] (/command)

Execute command and break out of the switch if the value given in /switch matches the value given here.

Examples
see /switch

Conditionals - if

/ife

(/command)

Use with /then, /elseif, and /else. The provided command must return true or false.

Examples
/setvar key=x foo |
/ife /test left=x rule=eq right=1 |
    /then pipe={{pipe}} /echo value is one |
/elseif pipe={{pipe}} /test left=x rule=eq right=foo |
    /then pipe={{pipe}} /echo value is foo |
/elseif pipe={{pipe}} /test left=x rule=eq right=bar |
    /then pipe={{pipe}} /echo value is bar |
/else pipe={{pipe}} /echo value is something else

/elseif

[pipe={{pipe}}] (/command)

Use with /ife, /then, and /else. The provided command must return true or false.

Examples
see /ife

/else

[pipe={{pipe}}] (/command)

Use with /ife, /elseif, and /then. The provided command will be executed if the previous /if or /elseif was false.

Examples
see /ife

/then

[pipe={{pipe}}] (/command)

Use with /ife, /elseif, and /else. The provided command will be executed if the previous /if or /elseif was true.

Examples
see /ife

World Info

/wi-list-books

[optional source=true]

Get a list of currently active World Info books. Use source=true to get a dictionary of lists where the keys are the activation sources.

Examples
/wi-list-books |
/echo The currently active WI books are: {{pipe}}
/wi-list-books source=true |
/json-pretty |
/comment Currently active WI books:{{newline}}```json{{newline}}{{pipe}}{{newline}}```

/wi-list-entries

[optional flat=true] (optional book name)

Get a list of World Info entries from currently active books or from the book with the provided name. Use flat=true to list all entries in a flat list instead of a dictionary with entries per book.

Examples
/wi-list-entries |
/map list={{pipe}}
    /getat index=entries {{item}} \|
    /map list=\{\{pipe\}\}
        /getat index=comment \\{\\{item\\}\\}
|
/echo Overview of WI entries in currently active books: {{pipe}}

Costumes / Sprites

/costumes

[optional recurse=false] (folder)

Get a list of costume / sprite folders, recursive by default.

Examples
/costumes Alice | /echo Alice's costumes: {{pipe}}
/costumes Alice/Winter | /echo Alice's winter costumes: {{pipe}}
/costumes recurse=false Alice | /echo Alice's top-level costumes only: {{pipe}}

Quick Replies

/qr-edit

[optional set=qrSetName] [optional label=qrLabel] (optional qrLabel)

Show the Quick Reply editor. If no QR set is provided, tries to find a QR in one of the active sets.

Examples
/qr-edit My QR From An Active Set
/qr-edit set=MyQrSet label=MyQr

/qr-add

[optional set=qrSetName] [optional label=qrLabel] (optional qrLabel)

Create a new Quick Reply and open its editor. If no QR set is provided, tries to find a QR in one of the active sets.

Examples
/qr-add New QR In Active Set
/qr-add set=MyQrSet label=MyNewQr

Chat Messages

/swipes-get

[optional message=messageId] (index)

Get the n-th swipe (zero-based index) from the last message or the message with the given message ID.

Examples
/swipes-get 5 |
/echo Swipe number five: {{pipe}}
/sub {{lastMessageId}} 2 |
/swipes-countget message={{pipe}} 5 |
/echo swipe number five: {{pipe}}

/swipes-list

[optional message=messageId]

Get a list of all swipes from the last message or the message with the given message ID.

Examples
/swipes-list |
/echo
/sub {{lastMessageId}} 2 |
/swipes-list message={{pipe}} |
/echo

/swipes-count

[optional message=messageId]

Get the number of all swipes from the last message or the message with the given message ID.

Examples
/swipes-count |
/echo
/sub {{lastMessageId}} 2 |
/swipes-count message={{pipe}} |
/echo

/swipes-index

[optional message=messageId]

Get the current swipe index from the last message or the message with the given message ID.

Examples
/swipes-index |
/echo
/sub {{lastMessageId}} 2 |
/swipes-index message={{pipe}} |
/echo

/swipes-add

(message)

Add a new swipe to the last message.

Examples
/sendas name=Alice foo |
/delay 1000 |
/swipes-add bar

/swipes-del

(optional index)

Delete the current swipe or the swipe at index (0-based).

Examples
/sendas name=Alice foo |
/delay 1000 |
/swipes-add bar |
/delay 1000 |
/swipes-del
/sendas name=Alice foo |
/delay 1000 |
/swipes-add bar |
/delay 1000 |
/swipes-add foobar |
/delay 1000 |
/swipes-del 0

/swipes-go

(index)

Go to the swipe. 0-based index.

Examples
/sendas name=Alice foo |
/delay 1000 |
/swipes-add bar |
/delay 1000 |
/swipes-add foobar |
/delay 1000 |
/swipes-go 0

/swipes-swipe

Trigger a new swipe on the current message.

Examples
/swipes-swipe |
/echo swiping has finished

/message-edit

[optional message=messageId] [optional append=true] (new text)

Edit the current message or the message at the provided message ID. Use append=true to add the provided text at the end of the message. Use {{space}} to add space at the beginning of the text.

Examples
/sendas name=Alice foo |
/delay 1000 |
/message-edit bar
/sendas name=Alice foo |
/delay 1000 |
/message-edit append=true bar

Time & Date

/timestamp

Returns the number of milliseconds midnight at the beginning of January 1, 1970, UTC.

Examples
/timestamp |
/echo

Async

/fireandforget

(command)

Execute a command without waiting for it to finish.

Examples
/fireandforget
    /delay 1000 \|
    /echo firing \|
    /delay 1000 \|
    /echo still firing
|
/echo outside

Undocumented

/fetch

(url)

UNDOCUMENTED

Examples
/fetch http://example.com |
/echo

/$

[optional query=cssSelector] [optional take=property] [optional call=property] (html)

UNDOCUMENTED

Examples
/fetch http://example.com |
/$ query=h1 take=textContent |
/echo

/$$

[optional query=cssSelector] [optional take=property] [optional call=property] (html)

UNDOCUMENTED

Examples
/fetch http://example.com |
/$$ query=p call=remove |
/echo

About

Library of helpful STScript commands for SillyTavern.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.5%
  • Python 1.5%