utils
randomstuff.utils
is a sub module that contains some useful functions to aid with the API interactions.
Functions
generate_uid
generate_uid
Generates a complex and safe to use unique ID. This is very useful when you need a unique key for AI response endpoint.
format_joke
format_joke
A simple method to turn a two-part joke into a string. It simply formats two-part joke in provided format, By default is: '{setup}... {delivery}'
format_to
(Optional)
format_to
(Optional)This is the format. In that format, {setup}
is replaced with setup
of the joke and {delivery}
with delivery
.
For example:
joke = client.get_joke()
formatted_joke = utils.format_joke(
joke,
format_to='{setup}... {delivery}'
)
print(formatted_joke.joke) # The formated joke
Type: str
get_safe_joke
get_safe_joke
A method that filters or ignores any unsafe joke. This method is made to be used in replacement to get_joke
method.
For example:
client = randomstuff.Client(api_key="key") # Or AsyncClient
joke = utils.get_safe_joke(client, type="any")
print(joke.safe) # Always prints `True`
print(joke.joke)
client
client
Your Client
or AsyncClient
instance.
Type: Union[
Client
,
AsyncClient
]
type
(Optional)
type
(Optional)Equivalent to Joke.type
Type: Union[
Client
,
AsyncClient
]
Last updated
Was this helpful?