Arrays are polyadic values that have 0 or more values of any kind, including
objects and other arrays. Specific values are accessed by their
INDEX, which is a number (or a numeric variable or
function).
Indexes are sequential integers that start at 0. If the index is negative, it
counts from the end of the array, with the last value at index -1.
${length${ARRAY}} is the number of values in the array.
${expr${length${ARRAY}} - 1} is the last index of the array.
Chat commands are messages that begin with an exclamation mark and are followed
by a COMMAND name and optional
ARGUMENTS. There are various default commands and custom commands may also be created with !addcommand.
Custom commands may have sections of their responses be
conditional, meaning that they will only be executed if a condition is met. A
conditional group begins with $[if] or $[unless], any number
of $[elseif]s, an optional $[else], and end with
$[endif].
Custom commands may use FUNCTIONs which are like
regular variables except that variables can only be accessed and
modified. Functions may accept ARGUMENTS and/or do something.
Function arguments are separated by spaces. Arguments can be quoted and special
characters can be escaped.
(space)
Escape with \, quote with ", quote with '
"
Escape with \, quote with '
$
Escape with \, quote with '
'
Escape with \, quote with "
\
Escape with \, quote with ' (if not followed by \ or ')
}
Escape with \, quote with ", quote with '
The names of functions (and other variables) are determined when
they are used, allowing them to contain variables themselves.
Loops allow parts of custom commands' responses to repeat.
You may loop while a condition is true with $[while], while a
condition is not true with $[until], or over items in
arrays with $[foreach].
Within the loop, you may use $[continue] to skip to the next iteration
of the loop or $[break] to exit the loop.
Objects are polyadic values that have any number of KEY-value pairs.
Keys are strings (or variables or functions)
and values can be of any kind, including arrays and other objects.
Various functions and commands give partly (or wholly)
random results. That randomness comes from a random number generator that is
suitable for generating strong cryptographic secrets, so if you were wondering
how random is !dice?, the answer is very random.
Advanced string matching and substition capability
Regular expressions are used for matching sections of a string and possibly
replacing it. The syntax is ugly and will not be described here. If you want to
learn about regular expressions, you will have to do that elsewhere.
Backtracking is disabled for greedy matches to prevent catastrophic
backtracking, so some patterns may not work properly.
Variables are set to values that can be used later by name
${VARIABLE}
Variables can be set with ${letVARIABLE VALUE} or
${setVARIABLE VALUE} and removed with
${unsetVARIABLE}. Variables can be retrieved using
${VARIABLE} or ${getVARIABLE [VALUE]}.
${let} can be used to set temporary variables which have monadic values
like strings and numbers, or polyadic values like arrays
and objects. Subvalues may be referenced by enclosing their key or
index between "[" and "]", or by putting their key after a ".".
${letvariable ${object}}${letvariable.key "some value"}${variable.key}some value
${set} can be used to set persistent variables which have only monadic
values like strings and numbers. They cannot contain polyadic values.
The names of variables (and functions) are determined when they are
used, allowing them to contain variables themselves.
${letvariable "A variable's value"}${letvarname variable}${${varname}}A variable's value
Creates a new custom command with the specified COMMAND name and
RESPONSE. The response may include variables and
functions. If you want to include ${ or $[ as-is in your response
then you will need to escape them with a backslash (\) like
\${….
OPTIONS may be specified before the response. The option names are
followed by an equals (=) or a space and the value. Options are separated from
each other by spaces.
-level (alias -ul)
The minimum user level for the command: broadcaster, moderator, or user.
-cooldown (alias -cd)
The minimum time (in seconds) that must pass before the command is used again.
Have the bot join/leave your chat and respond to commands and triggers
Required level: broadcaster
This command can be used from the bot's chat.
Using !join in the bot's chat causes the bot to join your chat and
respond to a default set of flags. Using !leave in
the bot's chat causes the bot to stop responding in your chat and leave it.
After having HelenOLoy join your chat, you should
/mod HelenOLoy
in
your chat to make it a moderator so that everything will work (e.g.,
!followsince).
If join is enabled in your chat, you will be able to use !leave
there as well. That will only work for you, the broadcaster, not for your
moderators.
Immediately $[break]s out of the loop. The remainder of the code in
the block will not be run and execution will continue after the
$[done]. It must occur between a $[while] or
$[foreach], and its corresponding $[done].
$[while${expr1}]This loop looks infinite$[break]$[done] but it is notThis loop looks infinite but it is not
$[continue] immediately loops, even if there is more code to run
before the end of the loop block. It must occur between a $[while] or
$[foreach], and its corresponding $[done].
$[else] creates a conditional block whose code will only be executed
if no other conditions have matched. It must come after $[if] or
$[unless] and any $[elseif]s, and before $[endif].
$[if${expr${random1000} > 750}]You are very lucky 🐻$[else]How unlucky for you 😢$[endif]You are very lucky 🐻
$[elseif] creates a conditional block whose code will only be executed
if VARIABLE is true. VARIABLE may be a regular
variable or a function. It must be
inside of ${ and }.
$[elseif] must come after a $[if] or $[unless] and
before the $[else] or $[endif]. You can have any number of
$[elseif]s.
You are $[if${equals${user.level} broadcaster}]a broadcaster$[elseif${equals${user.level} moderator}]a moderator $[else]a regular user$[endif]You are a broadcaster
$[foreach] creates a block whose code will be executed once for every
item in VARIABLE, which will be stored in ${loopvar}.
If VARIABLE is a regular variable, the loop
body will execute once. If it is an array, the body will be
executed as many times as there are items in the array.
If VARIABLE is a function then its return value
will be used.
$[foreach] must have a corresponding $[done].
$[if] creates a conditional block whose code will only be executed if
VARIABLE is true. VARIABLE may be a regular
variable or a function. It must be
inside of ${ and }.
$[if] must have a corresponding $[endif].
You are $[if${equals${user.level} broadcaster}]the broadcaster, $[endif]${user}.You are the broadcaster, Undeference.
$[unless] creates a conditional block whose code will only be executed
if VARIABLE is false. VARIABLE may be a regular
variable or a function. It must be
inside of ${ and }.
$[unless] must have a corresponding $[endif].
${lettarg ${randtarg}}$[unless${targ.id}]${lettarg.id "Unknown ID"}$[endif]Your ID is ${targ.id}Your ID is 248929134
$[until] creates a block whose code will be repeatedly executed as
long as VARIABLE is false. VARIABLE may be a
regular variable or a function. It
must be inside of ${ and }.
$[until] must have a corresponding $[done].
$[while] creates a block whose code will be repeatedly executed as
long as VARIABLE is true. VARIABLE may be a regular
variable or a function. It must be
inside of ${ and }.
$[while] must have a corresponding $[done].
${bind} calls FUNCTION with arguments
in ARRAY. Any argument checking the function does
will still be done, but it will look in the array instead of a normal arguments
list.
Run COMMAND from within the current command and return its result.
Standard user ${level} and !enable checks are not done. This
cannot currently be used to let lower level users use the commands
!join, !enable, or !command.
Removes items from OBJECT whose keys are in ARGUMENTS.
Returns an array with the values for those keys. The array
returned will contain empty items anywhere that an item did not exist in the
OBJECT.
${letobj ${objecttype object name example}}${delete${obj} name}
Evaluate a mathematical expression${expr} evaluates a mathematical expression and returns the result. All
of the normal math-type expressions are permitted as well as some things you might
not expect.
Unary operators—these operators precede an operand (like the - in -1)
!
Boolean not: if the operand is true, then it is false and vice versa
~
Bitwise not: flips all of its bits from 1 to 0 and vice versa
Binary operators—these operators take two operands (like the - in 2-1)
==
Numerical equality: true if both operands are equal, and false if they are not
!=
Numerical inequality: true if the operands are not equal, and false if they are
%
Modulus: gives the remainder of dividing the left-hand side by the right-hand side
**
Power: raises the left-hand side to the power of the right-hand side
^
Bitwise exclusive or: bits in the output will be 1 if the corresponding input bits are not equal to each other, and 0 otherwise
&
Bitwise and: bits in the output will be 1 if both corresponding input bits are 1, and 0 otherwise
|
Bitwise not: bits in the output will be 1 if either corresponding input bit is 1, and 0 otherwise
&&
Boolean and: the output will be true if both inputs are true, and false otherwise
||
Boolean or: the output will be true if one or both inputs are true, and false otherwise
The ?: ternary operator is permitted.
Functions (may be used without parentheses)
atan2(Y,X)
Returns the arctangent of Y/X
sin(X)
Returns the sine of X
cos(X)
Returns the cosine of X
exp(X)
Returns the natural logarithm (base e) to the power of X
log(X)
Returns the natural logarithm (base e) of X
sqrt(X)
Returns the positive square root of X—equivalent to X**(1/2)
Numbers may be specified using exponential notation with e or E. I.e., XeY means
X*(10**Y). Numbers are decimal (base 10) by default, but special notation can be
used to change that.
0bNUMBER
NUMBER is binary (base 2: 0-1)
0NUMBER, 0oNUMBER
NUMBER is octal (base 8: 0-7)
0xNUMBER
NUMBER is hexadecimal (base 16: 0-9, a-f)
Hexadecimal numbers contain numerals from 0 to 9 and a to f (inclusive), with
the letters a-f corresponding to the decimal values 10-15. The letters may be
uppercase or lowercase.
If you wish to group digits, you may use underscores (_) but not commas (,).
E.g., instead of 1,000,000, use 1_000_000.
Return the first ${index} of STR in the provided
STRING or ARRAY, starting at OFFSET. Returns -1
if it could not be found.
${index"Match the substring in the string" string}13${index"Match the substring in the string" string 14}27${index${arrayMatch the element in the array} element}2
${int} returns the integer part of the specified VALUE. If
the value is an array or an object then
you get the number of values. If the value is a non-numeric string, you will get
the value 0.
${length} takes an argument and returns the number of values it has. In
other words, this is the number of characters in a string or the number of
values in an array or object.
Your name is ${length${nick}} characters longYour name is 11 characters long
${let} sets a variable with the specified NAME to the
specified VALUE. The variable can have a simple value like a string
or a number, or it can be an ${array} or ${object}. Variables
set with ${let} only exist until the command ends.
If a variable with the specified name was (or becomes) declared with ${set}, that variable will be masked, meaning that it will become inaccessible in
the current command, but continues to exist.
${match} performs a regular expression PATTERN match on
STRING with the specified FLAGS. PATTERN is a
regular string, so escaping or quoting may be needed. Backtracking is disabled
for greedy matches for greedy matchesto prevent catastrophic backtracking.
Capture groups will be saved in variables with names corresponding to each
groups' number and name (if applicable).
Characters in FLAGS affect the matching.
m
Indicates the string contains multiple lines. ^ will only match the start of the first line and $ will only match the end of the last line.
s
Treat the string as a single line; . will match newlines.
i
Do case-insensitive matching.
x
Allow whitespaces and comments in PATTERN.
g
Match PATTERN repeatedly.
c
With g, keep the position of the previous match, which will be \G in PATTERN.
$[if${match${nick} ([aeiou]) i}]Found the vowel ${1}$[endif]Found the vowel uWhat vowels are there? $[while${match${nick}'([aeiou])' igc}]${1}$[done]What vowels are there? u e e e e
${push} adds the items of ARGUMENTS to the end of
ARRAY and returns ARRAY itself.
${letarr ${arraySome items}}${push${arr} in an array}Some items in an array${letarrA ${array1 2 3}}${letarrB ${arrayone two three}}${bindpush ${array${arrA}${arrB}}}1 2 3 one two three
${randtarg} returns an object representing a random
user in chat. The object returned is the same type as ${target}. The
object will stringify as though the display key had been referred to directly.
You cannot use keys directly but must store the result of ${randtarg}
first.
nick
This is the target user's Twitch login name.
name
Alias for the user's .nick.
id
The user's Twitch ID if it is known.
display
The user's display name (or .nick).
channel
The user's IRC channel name, usually # followed by .nick.
${replace} performs a regular expression PATTERN match on
STRING with the specified FLAGS and replaces the match in
the original string with REPLACEMENT. PATTERN and
REPLACEMENT are regular strings, so escaping or quoting may be
needed. Backtracking is disabled for greedy matches to prevent catastrophic
backtracking.
Capture groups may be referenced in REPLACEMENT. This is done by
having a backslash followed by the number of the capture group, or the name
enclosed in braces. Capture groups will be saved in variables with the names
corresponding to each groups' number and name (if applicable).
Characters in FLAGS affect the matching and are the same as
with ${match}.
m
Indicates the string contains multiple lines. ^ will only match the start of the first line and $ will only match the end of the last line.
s
Treat the string as a single line; . will match newlines.
i
Do case-insensitive matching.
x
Allow whitespaces and comments in PATTERN.
g
Match PATTERN repeatedly.
c
With g, keep the position of the previous match, which will be \G in PATTERN.
${rindex} returns the last index of STR in the provided
STRING or ARRAY before OFFSET. If
OFFSET is not provided, starts at the end of the string or array.
Returns -1 if it could not be found.
${rindex"Match the substring in the string" string}27${rindex"Match the substring in the string" string 26}13${rindex"Match the substring in the string" string 12}-1${rindex${arrayMatch the element in the array} element}2
${safeuri} tries to make a canonical URL from the provided
URI, optionally with BASEURL as the base URL. This is
similar to what web browsers do when they see links.
${set} sets a variable with the specified NAME to the
specified VALUE. The variable can only have a simple value like a
string or a number. Variables set with ${set} exist until they are
${unset}. They can be used in other commands.
If you attempt to store arrays or objects with
${set}, they will be stringified. You can use something like ${join} or ${tojson} to store arrays and objects persistantly (and then
${split} or ${json} to use them again later).
${slice} returns an array containing sequential items from
ARRAY starting at OFFSET and containing LENGTH
items. If OFFSET is not specified, it copies from the start. If
LENGTH is not specified, it copies until the end. If
LENGTH is specified, the resulting array will contain that many items
even if the input ARRAY does not have that many items.
This is a shallow copy, meaning any array or object items will be shared.
${split} the STRING into parts separated by the specified
DELIMITER and return an array containing those parts. If
PARTS is specified, the resulting array will contain up to that
number of items, with the last item containing any additional delimiters.
If DELIMITER is an empty string, ${split} returns an array
containing STRING's characters.
${substr} takes a STRING and returns a substring starting at
the specified OFFSET. The returned substring will have up to
LENGTH characters, if specified. If LENGTH is not
specified, the substring will continue until the end of the string.
If REPLACEMENT is specified, it replaces the characters in the
original string. The substring is still returned.
${letstr "In a while"}${substr${str} 5}while${letstr "In a while"}${substr${str} 5 0 "little "}${str}In a little while
${target} returns an object representing the user
whose name matches NAME. Partial name matching will be done if no
user has that name exactly. The object returned is similar to ${user}.
The object will stringify as though the display key had been referred to
directly.
You cannot use keys directly but must store the result of ${target}
(with ${let}) first.
nick
This is the target user's Twitch login name.
name
Alias for the user's .nick.
id
The user's Twitch ID if it is known.
display
The user's display name (or .nick).
channel
The user's IRC channel name, usually # followed by .nick.
${twitch.ban} tries to ban a Twitch user with the specified
USERID. You may specify a DURATION in seconds and/or a
REASON for the ban. On success, returns an object.
user_id
This is the USERID specified.
created_at
The date and time that the ban or timeout was placed.
end_time
The date and time that the timeout will end (if it will).
${twitch.bitsleaderboard} returns an array of objects containing
information about the channel's bits leaderboard. If DURATION is
specified (as day, week, month, year, or all), the results will be constrained
to the specified time period.
user_id
The Twitch user ID of a user on the bits leaderboard.
user_login
The login name of a user on the bits leaderboard.
user_name
The display name of a user on the bits leaderboard.
rank
The rank of a user on the bits leaderboards.
score
The number of bits cheered by a user on the bits leaderboard.
${twitch.channel} returns information about a Twitch channel. If no
BROADCASTERID is specified, returns information about the current
channel. Returns an object on success.
broadcaster_language
The two-letter code of the broadcaster's preferred language (or 'other').
game_id
The game ID.
game_name
The game name.
title
The title of the current or previous stream.
delay
The broadcaster's stream delay setting
tags
An array containing the channel's tags.
content_classification_labels
An array containing the channel's content classification labels.
is_branded_content
A boolean indicating if the channel has branded content.
${lettwchan ${twitch.channel}}$[if${twchan}]${broadcaster} last played ${twchan.game_name}$[endif]Undeference last played Cities: Skylines
${twitch.chatsettings} returns an object containing the channel's chat
settings. If an OBJECT is provided, it contains a set of new chat
settings to apply.
The return value contains these fields, and if an OBJECT is specified
then it may contain any of these fields:
emote_mode
A boolean indicating if all messages are required to contain emotes.
follower_mode
A boolean indicating if users must be following the channel in order to chat.
follower_mode_duration
If follower_mode is true, this is the the minimum number of minutes a user must be following the channel to be able to chat.
non_moderator_chat_delay
A boolean indicating if messages from non-moderator chatters will be delayed so that they can be moderated before being displayed.
non_moderator_chat_delay_duration
If non_moderator_chat_delay is true, this is the number of seconds (2, 4, or 6) that messages from non-moderators will be delayed.
slow_mode
A boolean indicating if there is a delay between chat messages from the same user.
slow_mode_wait_time
If slow_mode is true, this is the number of seconds (3-120) to users must wait between chat messages.
subscriber_mode
A boolean indicating if a user must be subscribed to the channel to be able to chat.
unique_chat_mode
A boolean indicating if repeated messages will be blocked.
${letsettings ${twitch.chatsettings}}${letcheck ${array"✖ Off""✔ On"}}Emote mode is ${check[${int${settings.emote_mode}}]}Emote mode is ✖ Off
${twitch.clips} returns an array containing objects with information
about the channel's clips. A channel can be specified by specifying a
BROADCASTERID.
Each clip object contains:
id
The clip's ID.
url
The clip's URL.
embed_url
A URL for embedding the clip on a website.
creator_id
The Twitch user ID of the user who created the clip.
creator_login
This field should exist but does not.
creator_name
The display name of the user who created the clip.
video_id
The ID of the video the clip came from, if available.
game_id
The ID of the game in the clip.
game_name
This field should exist but does not.
language
The two-letter code for the language of the broadcast (or 'other').
title
The clip's title.
view_count
The number of times the clip has been viewed.
created_at
The date and time when the clip was created.
duration
The length of the clip is seconds.
vod_offset
The position of the clip from the start of the video, in seconds.
${twitch.games} returns an array of
objects containing information about games. If there are arguments,
they are GAMENAMES to match (or an array of GAMENAMES).
id
The game's ID.
name
The game's name.
${letwc2 ${twitch.games wc2}}$[if${length${wc2}}]We're playing ${wc2[0].name}$[else]Wut?$[endif]We're playing WarCraft II: Tides of Darkness
${twitch.shieldmode} lets you get information about the Twitch chat's
shield mode. Optionally, STATUS is a boolean indicating whether to
turn shield mode on or off. If shield mode was/is enabled, returns an object.
is_active
A boolean value corresponding to whether shield mode is active.
moderator_id
The Twitch user ID of the moderator who enabled shield mode.
moderator_login
The Twitch login name of the moderator who enabled shield mode.
moderator_name
The Twitch display name of the moderator who enabled shield mode.
last_activated_at
The date and time when shield mode was enabled.
${letshield ${twitch.shieldmode}}Shield mode $[if${shield.is_active}]was activated by ${shield.moderator_name} at ${shield.last_activated_at}$[else]is not active$[endif].Shield mode is not active.
${twitch.stream} returns information about a Twitch stream. If no
USERID or USERNAME is specified, returns information about
the current stream. Returns an object on success.
id
The stream ID.
user_id
The broadcaster's Twitch user ID.
user_login
The broadcaster's login name.
user_name
The broadcaster's display name.
game_id
The game ID.
game_name
The game name.
title
The stream's title.
tags
An array containing the stream's tags.
viewer_count
The number of viewers watching the stream.
started_at
The date and time of when the broadcast began.
language
The two-letter code of the stream language (or 'other').
is_mature
A boolean indicating if the stream is intended for mature audiences.
${letstream ${twitch.stream}}$[if${stream}]${stream.user_name} is playing ${stream.game_name} with ${stream.viewer_count} viewer$[if${expr"${stream.viewer_count} != 1"}]s$[endif]$[else]Not live$[endif]Not live
${unset} removes a variable with the specified NAME that was
created by ${let} or ${set}. If two variables with the name
name exist, the one creates with ${let} will be removed first,
unmasking the one created with ${set}.
The arguments to the command${arg} is an array containing the command arguments
${arg[0]} contains the full argument string, with
subsequent array items being individual arguments, such that the first argument
is ${arg[1]} and so on.
The user's badges
This is an object containing the user's Twitch badges in the current chat. Keys
are the names of the badges and the value is the "version number".
Examples of some useful badges are admin, staff, subscriber, bits. Most badges
have a "version" of 1, but some have more meaningful "versions", like bits.
The channel name${channel} is an object with various keys related to the current chat.
${channel} will be stringified as though
${channel.name} was used directly.
Welcome ${user} to ${channel}!Welcome Undeference to #undeference 2454252 undeference!
name
The channel name. This is the same as ${broadcaster.nick}.
channel
The actual IRC channel name. This is the same as #${channel.name}.
id
The channel ID. This is the same as ${broadcaster.id}.
Error from eval${evalerror} is the error message of the last ${eval} you used
in this command, if it failed. It can be used to test if the last ${eval} failed.
The message's tags
This is an object containing the values of the message's IRC tags. This should
not generally be needed. See Twitch IRC Tags
documentation for more information (but note that the values have been unescaped).