Enforcer Script - Commands that set variables

setvar

Syntax:

!setvar <variable-name>::<value>

Example:

!setvar x::42

Description:

Sets the value of a variable.  The value is treated as a simple string.  


setvarex

Syntax:

!setvarex <variable-name>::<expression>

Example:

!setvarex x::20 22 plus

Description:

Treats the second argument as an expression and evaluates it, then sets the variable to the evaluation result.

Expressions are a combination of values and operators, written in Reverse Polish Notation, which means that the operator is written after the value(s) on which it operates.  In the example above, "plus" is an operator that takes two arguments, in this case, 20 and 22, treats them as integers and delivers their sum.  So the example above will set the value of variable x to 42.

The expression argument is first separated into "atoms", which are substrings separated by whitespace.  In the above example, there are three atoms: "20", "22" and "plus".  You can make an atom that contains a space by enclosing it in either double or single quotes, as in the following example:

!setvarex  s::'$x' "forty two" streq

This expression also contains three atoms.  The first is "42" - the expansion of the previously-assigned x, the second is "forty two" and the third is "streq", which compares two strings and returns "true" if they're the same, and "false" if they're different (which they are in this case).  The single quotes around the expansion of x and the double quotes around "forty two" just serve to demark the atoms - they are not considered a part of the atoms.  If you need to group words that contain a single quote into an atom, you can surround it with double quotes, and vice versa.

The following operators are defined:

Operator Arg Count Description
istrue 1 Returns "true" if the argument represents a true value, "false" if not. Synonymn for asBool
isfalse 1 Returns "false" if the argument represents a true value, "true" if not.
eq 2 Returns "true" if the 2 operands, treated as integers, are equal, "false" otherwise
ne 2 Returns "false" if the 2 operands, treated as integers, are equal, "true" otherwise<
gt 2 Treats the operands as integers, and returns "true" if the first operand is greater than the second operand, "false" otherwise
lt 2 Treats the operands as integers, and returns "true" if the first operand is less than the second operand, "false" otherwise
ge 2 Treats the operands as integers, and returns "true" if the first operand is greater than or equal to the second operand, "false" otherwise
le 2 Treats the operands as integers, and returns "true" if the first operand is less than or equal to the second operand, "false" otherwise
streq 2 Treating the operands as strings, returns "true" if the two operands are equal, "false" otherwise
strne 2 Treating the operands as strings, returns "false" if the two operands are equal, "true" otherwise
strgt 2 Treating the operands as strings, returns "true" if the first operand is alphabetically greater than the second, "false" otherwise
strlt 2 Treating the operands as strings, returns "true" if the first operand is alphabetically less than the second, "false" otherwise
strge 2 Treating the operands as strings, returns "true" if the first operand is alphabetically greater than or equal to the second, "false" otherwise
strle 2 Treating the operands as strings, returns "true" if the first operand is alphabetically less than or equal to the second, "false" otherwise
contains 2 The first operand should be a list (see below). Returns "true" if the list in the first operand contains the second operand string as a member, "false" otherwise
asBool 1 Converts the operand to "true" or "false"
asInteger 1 Converts the operand to an integer value
asInterval 1 Converts the operand to an interval (see below)
toSeconds 1 Treats the operand as an interval (see below), and converts it to seconds
plus 2 Converts the arguments to integers and returns their sum
minus 2 Converts the arguments to integers and returns argument_1 - argument_2
and 2 Treats the arguments as truth values and returns "true" if both arguments are true, otherwise "false'
or 2 Treats the arguments as truth values and returns "true" if either argument is true, otherwise "false'
csv2l 1 Converts a comma-separated string to a list (see below)
l2csv 1 Converts a list (see below) into a comma-separated string
select variable Returns the specified argument (see below)
rand 1 Returns a random integer between 1 and the argument value (inclusive)
element 2 Treats argument_1 as a list and argument_2 as an integer, and returns the element in the position given by argument_2


List values are strings that begin and end with a colon (:), containing substrings separated by colons.  These substrings are the individual list elements.

An Interval is a string of the form "NdNhNmNs" representing a duration in time, where the "N"s are integers, indicating days, hours, minutes and seconds respectively.  So "0d1h30m0s", "1h30m", "1h29m60s" and "90m" all mean "90 minutes".  As the example shows, you may omit parts of the interval where the integer is zero.

select is an operator that takes a variable number of operands and returns one of them.  The operand immediately to the left of the select specifies how many other operands there are.  For example:

v4 v3 v2 v1 2 5 select

The 5 to the left of select indicates that the previous 5 atoms are operands to select.  The operand to the left of that, 2 in the example, is the selector - it specifies which of the remaining operands should be returned, counting leftwards and starting at 1.  In this case, the select expression will return "v2".

element is similar, except that it makes a selection from the elements of a list, rather than from a group of operands, and also that list elements are numbered from left to right.  So the list version of the above would be:

":v1:v2:v3:v4:" 2 element

which again would return "v2"


checkonline

Syntax:

!checkonline <variable-name>::<user>

Example:

!checkonline NueOnline::Nue Broome

Description:

Sets the value of a variable to "true" or "false", depending on whether the specified user is online.  The user may be specified either by name or by key.

 

No comments:

Post a Comment