Expressions in @MenuBuilderBot messages

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

  1. {2+3} => 5
  2. {2*3 + 5} => 11
  3. {(10-1) * (11-2)} => 81
  4. {%balance% * 67 * 1.02} => Depends on user balance

Allowed values

You can use in expressions:

  1. Numeric values with "." as decimal point:
    1
    100
    100.99
    0.81
  2. Numeric variable (balance etc.) values via macros
    %balance%
    %myvariable%
  3. 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):

  1. Math operators: +, -, *, /
    {2 + 1}, {3 * 3}
  2. Unary operators: +, -
    {-1 * 3}
  3. Division with round down to the nearest integer: //
    { 10 // 3 } => 3
  4. Power (x power of y): **, pow(x, y) - use when ** breaks markdown.
    { 2 ** 5 } => 32
    { pow(2, 5) } => 32

Math functions

  1. 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"
  2. 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

  1. round(xxx.xx)
    "bankers' rounding" to the nearest integer
    {round(100.01)} = 100
    {round(100.99)} = 101
  2. 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
  3. floor(xxx.xx)
    round down to the nearest integer
    {floor(100.11)} = 100
    {floor(100.99)} = 100
  4. ceil(xxx.xx)
    round up to the nearest integer
    {floor(100.11)} = 101
    {floor(100.99)} = 101

Random values

  1. randi(A, B) - random integer value between A and B (including A and B)
  2. randf(A, B) - random float value between A and B (including A and B)
  3. rands() - number "1" with random sign: -1 or +1
  4. 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

  1. 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

  1. Your balance is {%balance% * 100} USD
  2. 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.

All @MenuBuilderBot tutorials

  1. https://telegra.ph/All-MenuBuilder-Tutorials-06-29

Report Page