Utils

TagScriptEngine.utils.truncate(text: str, *, max: int = 2000, var: str = '...') str[source]

Truncate the given string to avoid hitting the character limit.

Parameters:
  • text – The string to be truncated.

  • max – On what character length the string should be truncated.

  • var – The custom string used for trunication (defaults to ‘…’).

Returns:

  • str – The truncated content.

  • .. versionadded:: 3.2.0

TagScriptEngine.utils.escape_content(string: str) str[source]

Escapes given input to avoid tampering with engine/block behavior.

Returns:

The escaped content.

Return type:

str

async TagScriptEngine.utils.maybe_await(func: Callable[[...], T | Awaitable[T]], *args: Any, **kwargs: Any) T | Any[source]

Await the given function if it is awaitable or call it synchronously.

Returns:

The result of the awaitable function.

Return type:

Any