String Utilities API Reference

class toolbox.strings.MarkdownFormat(value)[source]

An Enum to flag strings with the types of formatting that should be removed.

ALL = 1023

Used to remove all possible formatting.

BOLD = 8

Used to remove bold caused by 2 asterisks.

CODE_BLOCK = 32

Used to remove code blocks caused by backticks.

ITALIC_ASTERISK = 4

Used to remove italic caused by asterisks.

ITALIC_UNDERSCORE = 2

Used to remove italic caused by underscores.

MULTI_CODE_BLOCK = 64

Used to remove multiline code blocks caused by 3 backticks.

MULTI_QUOTE = 256

Used to remove multiline quotes caused by 3 bigger thans at the start of the line followed by a whitespace character.

NONE = 0

Refers to no formatting.

QUOTE = 128

Used to remove quotes caused by a bigger than at the start of the line followed by a whitespace character.

SPOILER = 512

Used to remove spoilers caused by 2 pipes.

STRIKETHROUGH = 1

Used to remove strikethroughs caused by 2 tildes.

UNDERLINE = 16

Used to remove underlining caused by 2 underscores.

toolbox.strings.format_dt(time: datetime.datetime, style: Optional[str] = None) str[source]

Convert a datetime into a Discord timestamp. For styling see this link: https://discord.com/developers/docs/reference#message-formatting-timestamp-styles

Parameters
  • time (datetime.datetime) – The datetime to convert.

  • style (str, optional) – The style to use for the timestamp, by default None.

Returns

The formatted timestamp.

Return type

str

toolbox.strings.is_invite(string: str, *, fullmatch: bool = True) bool[source]

Returns True if the provided string is a Discord invite, otherwise False.

Parameters
  • string (str) – The string to check.

  • fullmatch (bool) – Whether to check if the string is a full match, by default True.

Returns

Whether the string is a Discord invite.

Return type

bool

toolbox.strings.is_url(string: str, *, fullmatch: bool = True) bool[source]

Returns True if the provided string is a valid http URL, otherwise False.

Parameters
  • string (str) – The string to check.

  • fullmatch (bool) – Whether to check if the string is a full match, by default True.

Returns

Whether the string is an URL.

Return type

bool

toolbox.strings.remove_markdown(content: str, formats: toolbox.strings.MarkdownFormat = MarkdownFormat.ALL) str[source]

Removes the markdown formatting from Discord messages.

Parameters
  • content (str) – The str object, which needs their content cleaned from Discord’s markdown formatting.

  • formats (MarkdownFormat) – The IntFlag of the formatting that needs to be removed. Default is MarkdownFormat.ALL. Multiple can be supplied by using bitwise OR. Matches for MarkdownFormat.MULTI_CODE_BLOCK and MarkdownFormat.CODE_BLOCK don’t remove other formatting found inside them.

Returns

The cleaned string without markdown formatting.

Return type

str

toolbox.strings.utcnow() datetime.datetime[source]

A short-hand function to return a timezone-aware utc datetime.

Returns

The current timezone-aware utc datetime.

Return type

datetime.datetime