utils
randomstuff.utils
is a sub module that contains some useful functions to aid with the API interactions.
All functions are library specific and are not provided or suggested by API.
In order to use this module, You have to import it explicitly like this:
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:
Type: str
If the passed joke type is single, It silently ignores it and returns the passed joke as it is. (So, this technically raises no error so you can use it for general usage without having to handle any error.)
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.
It ignores any joke whose safe
attribute is False
and fetches another joke. Here, A question is raised that won't it cause rate-limit because of calling API so many times. The answer is, No. Usually jokes are returned with safe
attribute as True
there is a small chance of getting an unsafe joke. This method handles that chance. So, it has hardly noticeable affect.
For example:
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