utils
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
randomstuff.utils
is a sub module that contains some useful functions to aid with the API interactions.
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
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}'
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)
type
(Optional)Equivalent to Joke.type
Type: Union[
Client
,
AsyncClient
]
joke = client.get_joke()
formatted_joke = utils.format_joke(
joke,
format_to='{setup}... {delivery}'
)
print(formatted_joke.joke) # The formated joke