functions ¶
Shared Utility Functions for Tux Bot.
This module contains common utility functions used throughout the Tux Discord bot, including text processing, time conversion, parameter validation, and documentation formatting utilities.
Functions:
-
truncate–Truncate a string to a specified length.
-
strip_formatting–Strip formatting from a string.
-
parse_time_string–Convert a string representation of time into a datetime.timedelta object.
-
convert_to_seconds–Convert a formatted time string with the formats Mwdhms.
-
seconds_to_human_readable–Convert a number of seconds into a human readable string.
-
is_optional_param–Check if a parameter is optional.
-
get_matching_string–Match the given argument to a specific string based on common usage.
-
generate_usage–Generate the usage string for a command.
-
docstring_parameter–Parameterize docstrings with format-style substitution.
Functions¶
truncate ¶
Truncate a string to a specified length.
If the string is longer than the specified length, it will be truncated and an ellipsis will be appended. Otherwise, the original string is returned.
Parameters:
Returns:
-
str–The truncated string.
strip_formatting ¶
parse_time_string ¶
Convert a string representation of time into a datetime.timedelta object.
Parameters:
-
time_str(str) –The string representation of time to convert. (e.g., '60s', '1m', '2h', '10d')
Returns:
-
timedelta–The timedelta object representing the time string.
Raises:
-
ValueError–If the time format is invalid.