bot_api.util package

Submodules

bot_api.util.color_util module

class ColorUtil[source]

Bases: ABC

static to_hex(color: Color | None) str | None[source]

Converts the specified Color object to a hex triplet string representation.

The hex triplet consists of six hexadecimal digits representing an RGB color, e.g., “0099CC”.

Parameters:

color (Color) – The Color object to convert to a hex triplet.

Returns:

A string representing the color as a hex triplet of six hexadecimal digits, or None if the color is None.

Return type:

str

static from_string(string: str | None) Color | None[source]

Creates a color from a string. Currently, only numeric RGB values are supported.

This method works the same as from_hex except that it requires a hash sign before the hex value. An example of a numeric RGB value is “#09C” or “#0099CC”, which both represent the same color.

Parameters:

string (str) – A string containing either three or six hexadecimal RGB values like “#09C” or “#0099CC”.

Returns:

The created Color object, or None if the input parameter is None.

Return type:

Color

Raises:

ValueError – If the input string is not in the valid numeric RGB format.

static from_hex(hex_triplet: str) Color[source]

Creates a color from a hex triplet.

A hex triplet is either three or six hexadecimal digits that represent an RGB color. An example of a hex triplet is “09C” or “0099CC”, which both represent the same color.

Parameters:

hex_triplet (str) – A string containing either three or six hexadecimal numbers like “09C” or “0099CC”.

Returns:

The created Color object.

Return type:

Color

Raises:

ValueError – If the input string is not a valid hex triplet.

bot_api.util.country_code_util module

class CountryCodeUtil[source]

Bases: object

Country code utility class.

static local_country_code()[source]

Get the local country code based on the current locale.

Returns:

The two-letter country code in uppercase if found, None otherwise.

Return type:

str or None

static to_country_code(code)[source]

bot_api.util.math_util module

class MathUtil[source]

Bases: ABC

Math utility class.

static clamp(value: float, min_value: float, max_value: float) float[source]

Clamps a value to the inclusive range of min and max.

Parameters:
  • value – The value to be clamped.

  • min_value – The lower bound of the result.

  • max_value – The upper bound of the result.

Returns:

The clamped value.

Module contents

class ColorUtil[source]

Bases: ABC

static to_hex(color: Color | None) str | None[source]

Converts the specified Color object to a hex triplet string representation.

The hex triplet consists of six hexadecimal digits representing an RGB color, e.g., “0099CC”.

Parameters:

color (Color) – The Color object to convert to a hex triplet.

Returns:

A string representing the color as a hex triplet of six hexadecimal digits, or None if the color is None.

Return type:

str

static from_string(string: str | None) Color | None[source]

Creates a color from a string. Currently, only numeric RGB values are supported.

This method works the same as from_hex except that it requires a hash sign before the hex value. An example of a numeric RGB value is “#09C” or “#0099CC”, which both represent the same color.

Parameters:

string (str) – A string containing either three or six hexadecimal RGB values like “#09C” or “#0099CC”.

Returns:

The created Color object, or None if the input parameter is None.

Return type:

Color

Raises:

ValueError – If the input string is not in the valid numeric RGB format.

static from_hex(hex_triplet: str) Color[source]

Creates a color from a hex triplet.

A hex triplet is either three or six hexadecimal digits that represent an RGB color. An example of a hex triplet is “09C” or “0099CC”, which both represent the same color.

Parameters:

hex_triplet (str) – A string containing either three or six hexadecimal numbers like “09C” or “0099CC”.

Returns:

The created Color object.

Return type:

Color

Raises:

ValueError – If the input string is not a valid hex triplet.

class CountryCodeUtil[source]

Bases: object

Country code utility class.

static local_country_code()[source]

Get the local country code based on the current locale.

Returns:

The two-letter country code in uppercase if found, None otherwise.

Return type:

str or None

static to_country_code(code)[source]
class MathUtil[source]

Bases: ABC

Math utility class.

static clamp(value: float, min_value: float, max_value: float) float[source]

Clamps a value to the inclusive range of min and max.

Parameters:
  • value – The value to be clamped.

  • min_value – The lower bound of the result.

  • max_value – The upper bound of the result.

Returns:

The clamped value.