Expressions in @MenuBuilderBot messages
We extended the mechanism of macros. Macros allowed admins to add some dynamic and/or user-related information to menu messages in @MenuBuilderBot.
Русский перевод, который любезно предоставлен переводчиком Яндекса, здесь.
Now you can use expressions to define some light mathematical expressions with numeric constants and variable values.
Conditions that can be used in buttons are described in a separate manual.
How expressions look like
Expressions should be placed in the braces: {expression}.
You can combine all allowed values and operations (see below) in a single or several expressions. You can use spaces inside the expressions if you want to: they will be ignored.
Examples: {expression} => result
- {2+3} => 5
- {2*3 + 5} => 11
- {(10-1) * (11-2)} => 81
- {%balance% * 67 * 1.02} => Depends on user balance
Allowed values
You can use in expressions:
- Numeric values with "." as decimal point:
1
100
100.99
0.81 - Numeric variable (balance etc.) values via macros
%balance%
%myvariable% - Service macros with numeric value (referral system etc.)
%refcount%
%userid%
Available operations
You can use the next set of operations (may be extended in future):
- Math operators: +, -, *, /
{2 + 1}, {3 * 3} - Unary operators: +, -
{-1 * 3} - Division with round down to the nearest integer: //
{ 10 // 3 } => 3 - Power (x power of y): **, pow(x, y) - use when ** breaks markdown.
{ 2 ** 5 } => 32
{ pow(2, 5) } => 32
Math functions
- min(A, B, C, D...) - minimal value from the given list
Maximal length of the list - 10 values. For greater list the result will be always "0" - max(A, B, C, D...) - maximal value from the given list
Maximal length of the list - 10 values. For greater list the result will be always "0"
Rounding functions
- round(xxx.xx)
"bankers' rounding" to the nearest integer
{round(100.01)} = 100
{round(100.99)} = 101 - round(xxx.xx, y)
"bankers' rounding" to the y'th valuable sign
{round(100.01, 1)} = 100.0
{round(100.11, 1)} = 100.1
{round(100.99, 2)} = 100.99
{round(100.99, 1)} = 101.0 - floor(xxx.xx)
round down to the nearest integer
{floor(100.11)} = 100
{floor(100.99)} = 100 - ceil(xxx.xx)
round up to the nearest integer
{floor(100.11)} = 101
{floor(100.99)} = 101
Random values
- randi(A, B) - random integer value between A and B (including A and B)
- randf(A, B) - random float value between A and B (including A and B)
- rands() - number "1" with random sign: -1 or +1
- randl(A, B, C, D...) - random value from the given list
Maximal length of the list - 10 values. For greater list the result will be always "0"
When is used in the expressing, randi(A,B) will be replaced with a random number, and you can apply any other supported operators/functions to it.
Example of usage in a message:
You got {randi(1,10) * 2} apples
String functions
- bool_symb(A, B, C) - If A is TRUE shows B-string. if A is FALSE shows C-string
{ bool_symb( (%complete% == 1), "✅", "❌") }
Warning! This function consumes 0.1 function token per use.
Message examples
- Your balance is {%balance% * 100} USD
- You have %refcount% referrals. Write us and you'll get 0.5$ for every 10 refs and 2$ bonus for every 100 refs.
Now you'll get: {%refcount%//10 * 0.5 + %refcount%//100 * 2}
Limitations
Expressions cannot be nested. Expression:
{ a + {b + c} }
Is nested and will not be parced correctly. All incorrect expressions will be left unprocessed or may be partially processed.