Docs

Introduction

Prerequisites

UtilsX works with Python 3.5.3 or higher, this is because UtilsX relies on discord.py, if you would wish to have lower Python version support you are free to remove the discord folder in the UtilsX pip installation location.

Installation

You can directly get the library from PyPi:(python3 -m | py -3 -m) pip install utilsx

Quickstart

A minimal discord bot

1Fetching example...
So okay, lets get started! Using UtilsX is not that different than using the default discord.py library. The good thing about UtilsX is that you still have all your features from discord.py, the only difference is that you have some more features and that you have to use UtilsX its classes as meta classes in place of discord.py its meta classes. As you can see in the example, instead of making our bot class using commands.Bot we'll use BotX from utilsx.discord. (This isn't required as default for UtilsX to work module but its a shorter/easier way to create your bot instance.)

Its good practice to not put your commands/functions in your main instance. So UtilsX supports Cog support, a cog instance can be initialized like in the example. Just like our Bot instance the UtilsX Cog instance has all functions from the discord.py cog class. In UtilsX you can send an embedded message as easy as a normal message using self.embed(target, message, *args). This then constructs your embed and sends it.

A minimal console printer

1Fetching example...
UtilsX pretty printer transforms your CLI from a plain old gray and black CLI to a fancy rainbow! Well not really but you could do it if you wanted to. We use the pretty printer to make our products look more professional. Its not even hard to do it, first of all we have to setup our pretty printer, we can do this by doing var = Prettier(*args), yeah, thats all! In the example all the text we send (if we don't use other color codes) will be yellow. If you want to set another color you can provide a color code or use our enum codes. (like shown in the example).

The Prettier.print() statement takes a required message argument. But if you want to add a timestamp that will be formatted and shown before the message you can provide a datetime object.

Discord

The discord module was developed to be able to create discord.py bots more easy, it provides extra handlers and is super easy to implement! No functions have been removed, only shortcuts have been added to make your development process easier than ever!

BotX

class utilsx.discord.BotX:
The shorter way to create a discord.py bot instance. This also includes a few extra default functions.

Parameters:


Attributes:

  • prefix (Union[str, callable, List[str]]) - The bot instance its prefix, default is '!'
  • description (str) - The bot instance its description.
  • case_insensitive (bool) - If the bot will reply to all commands or only the case correct commands, default is True. (replies to all)
  • intent (discord.Intents) - The discord intents object that will be applied.
  • BotX.get_case_insensitive() -> bool

    Retrieves if the bot its case_insensitive status.

  • BotX.get_description() -> str

    Retrieves the bot description.

  • BotX.get_default_prefix(*args, **kwargs) -> str

    Retrieves the bot prefix.

  • BotX.run(token)
    Runs the bot instance.

    Parameters:

  • BotX.load_extensions(extensions)
    BotX.unload_extensions(extensions)
    Loads/unloads all extensions from a list, yields nothing for each extension.

    Parameters:

    • extensions (List[str]) - A list of extensions.
  • BotX.load_cogs(cogs)
    BotX.unload_cogs(cogs)
    Loads/unloads all cogs from a list

    Parameters:

    • cogs (List[Cog]) - A list of cog objects.
  • Here is a little example that will start your bot in only a few lines!
    1Fetching example...

Cog

class utilsx.discord.Cog():
The commands.Cog implemented Cog object. This processes the bot COG object.

Attributes:

  • message_handler (MessageHandler) - The message handler object, default is empty.
  • embed_handler (EmbedHandler) - The default embed handler object, default is empty.
  • footer_handler (FooterHandler) - The footer handler object, default is empty.
  • author_handler (AuthorHandler) - The author handler object, default is empty.
  • Cog.handle_message(message, format_args, handler_enabled)
    Handles all messages using the set message handler object.

    Parameters:

    • message (str) - The message that should get processed.
    • format_args (dict) - The format arguments that will be implemented in the prefix and suffix.
    • handler_enabled (bool) - If the message should get handled using the set message handler object.
  • Cog.send(target, message, *, tts, embed, file, files, nonce, delete_after, allowed_mentions, handler_enabled, format_args )
    Processes a message and forwards it to the default discord.py send method.

    Parameters:

    • target (abc.Messagable) - The location where the message should get sent to.
    • message (str) - The message that should get processed. .
    • message (str) - The location where the message should get sent to.
    • tts (bool) - If TTS should be enabled for the message.
    • embed (discord.Embed) - A discord.py embed object for sending embeds the old classical way.
    • file (discord.File) - A discord.py file that will be sent in the message.
    • files (List[discord.File]) - A list of discord.py files that will all be sent in the message.
    • nonce (int) - The nonce repl value.
    • delete_after (float) - The amount of seconds the message should be visible.
    • allowed_mentions (discord.AllowedMentions) - Controls the mentions being processed in this message.
    • handler_enabled (bool) - If the message should get handled using the set message handler object.
    • format_args (dict) - The format arguments that will be implemented in the prefix and suffix.

    Returns:

  • Cog.embed(target, message, *, title, raw, handler_enabled, color, format_args, image, thumbnail, footer, author, fields)
    Formats an embed and forwards it to the default discord.py send method.

    Parameters:

    • target (abc.Messagable) - The location where the message should get sent to.
    • message (str) - The message that should get processed. .
    • title (str) - The title for the embed.
    • raw (str) - The non embedded content.
    • handler_enabled (bool) - If the message should get handled using the set message handler object.
    • color (Union[discord.Color, int]) - The color of the embed bar.
    • format_args (dict) - The format arguments that will be implemented in the prefix and suffix.
    • image (str) - The url for a image that will be set as the embed image.
    • thumbnail (str) - The url for a image that will be set as the embed thumbnail.
    • footer (Footer) - A UtilsX footer object that will format the embed footer section.
    • author (Author) - A utilsX author object that will format the embed author section.
    • fields (List[Field]) - A list (up to 25) objects that will format the embed fields.
    • get_embed (bool) - If this boolean is set to true it will return the generated embed object.

    Returns:

Exceptions

module utilsx.discord.exceptions
The utilsx.discord exceptions.

  • exceptions.UtilsXDiscordException()
    The base exception for the UtilsX discord section!
  • exceptions.MissingFormatArguments()
    Exception that gets thrown when a .format raises an error due to missing keys.

Objects

module utilsx.discord.objects
UtilsX its data objects, these are used in the handlers and embeds.

  • objects.Embed(*, color, title, image, thumbnail)
    The embed object that UtilsX can process.

    Attributes & parameters:

    • color (Union[discord.Color, int]) - The color of the embed bar.
    • title (str) - The title for the embed.
    • image (str) - The url for a image that will be set as the embed image.
    • thumbnail (str) - The url for a image that will be set as the embed thumbnail.
  • objects.Footer(*, text, icon_url, timestamp)
    The embed object that UtilsX can process.

    Attributes & parameters:

    • text (str) - The text that will be visible in the footer.
    • icon_url (str) - An image url for the footer icon.
    • timestamp (bool) - If a timestamp should be visible.
  • objects.Author(name, *, url, icon_url)
    The embed object that UtilsX can process.

    Attributes & parameters:

    • name (str) - The text that will be in the author name field.
    • url (str) - The url to what the author section should link.
    • icon_url (str) - An image url for the author icon.
  • objects.Field(name, value, *, inline)
    The embed object that UtilsX can process.

    Attributes & parameters:

    • name (str) - The title for the field.
    • value (str) - The main content for the field.
    • inline (bool) - If the field should be inline.

Handlers

module utilsx.discord.handlers
UtilsX its discord data handlers, these process and handle all (related) data that goes through the cog.

  • handlers.MessageHandler(*, prefix, suffix)
    The object that handles all messages that are sent through the Cog object.

    Attributes & parameters:

    • prefix (str) - The string that will be prepended.
    • suffix (str) - The string that will be appended.

    MessageHandler.process(message, **kwargs)
    Message processor for the MessageHandler.

    Parameters:

    • message (str) - The message that will be processed.
    • **kwargs (str) - The formatting for the message.

    Raises:

  • handlers.FooterHandler(footer)
    The object that handles embed footers.

    Parameters:

    • footer (Footer) - The default footer object.

    FooterHandler.process(obj)
    Message processor for the MessageHandler.

    Parameters:

    • obj (Union[Footer, None]) - The new provided footer.

    Returns:

    • Union[Footer, None] - A valid footer object or None
  • handlers.AuthorHandler(footer)
    The object that handles the embed author field.

    Parameters:

    • author (Author) - The default author object.

    AuthorHandler.process(obj)
    Message processor for the MessageHandler.

    Parameters:

    • obj (Union[Author, None]) - The new provided author.

    Returns:

    • Union[Author, None] - A valid author object or None
  • handlers.EmbedHandler(footer)
    The object that handles the general embed structure.

    Parameters:

    • embed (Embed) - The default embed object.

    EmbedHandler.process(obj)
    Message processor for the MessageHandler.

    Parameters:

    • obj (Union[Embed, None]) - The new provided embed.

    Returns:

    • Union[Embed, None] - A valid embed object or None

Console

UtilsX its solution for easily formatting your consoles.

Prettier

module utilsx.console.Prettier
Prettier can make your programs look more professional with almost no effort!

Parameters:

  • datetime_format (str) - The datetime format that your entered datetime object will take. The default format is `[%y-%d-%m %H:%M:%S] `.
  • default_text_format (str) - The default way text will be formatted in a print. This can be a color, format or background. (or combined)
  • colors_enabled (bool) - If colors should be enabled in the console. If false it will strip all color codes from the message.
  • auto_strip_message (str) - If the pretty printer should automatically apply the python .strip() method to the content.
  • Prettier.clear_colors(msg)
    Clears all known color codes from a given message.

    Parameters:

    • msg (str) - The message that is the target.

    Returns:

    • str - A color code stripped string.
  • Prettier.print(message, *, time)
    Pretty prints a given message.

    Parameters:

    • message (str) - The message that must be pretty printed.
    • time (datetime) - The printed datetime object. (Optional)
  • Prettier.format(message, *, time)
    Formats a message, this method is also called in the Prettier print statement!

    Parameters:

    • message (str) - The message that must be formatted.
    • time (datetime) - The formatted datetime object. (Optional)

    Returns:

    • str - A formatted string.
  • Prettier.format_timestamp(time)
    Formats a datetime object, this method is also called in the Prettier format statement!

    Parameters:

    • time (datetime) - The datetime object that must be formatted

    Returns:

    • str - A formatted datetime object.

Formats

module utilsx.console.Formats
Enum for console formats/styling codes.

NOTE: Some CLI's may not support some formatting.

Example:
print(f"{Formats.underline.value}Underline text{Formats.default.value}")

Attributes:

default, dim, underline, blink, inverted, hidden

Colors

module utilsx.console.Colors
Enum for console color codes.

NOTE: Some CLI's may not support some colors.

Example:
print(f"{Colors.yellow.value}Yellow text{Colors.default.value}")

Attributes:

default, black, red, green, yellow, blue, magenta, cyan, light_gray, dark_gray, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, white

Backgrounds

module utilsx.console.Backgrounds
num for console background color codes.

NOTE: Some CLI's may not support some background colors.

Example:
print(f"{Backgrounds.red.value}This text has a red background{Backgrounds.default.value}")

Attributes:

default, black, red, green, yellow, blue, magenta, cyan, light_gray, dark_gray, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan, white