Skip to content

disckit v0.9

Choose a tag to compare

@Jiggly-Balls Jiggly-Balls released this 28 May 13:40
· 101 commits to main since this release

The v0.9 update brings a lot of more features, enhanced code and some breaking changes.

The major change in this version is the rework done to all embeds, namely-

  • disckit.utils.ErrorEmbed
  • disckit.utils.MainEmbed
  • disckit.utils.SuccessEmbed

Their __init__ signatures now allow you to make embeds like so-

from disckit.utils import MainEmbed

MainEmbed(
    "This is a title",
    "This is the description"
)
MainEmbed("Now I only have a description")
MainEmbed(title="I can take in regular kwargs too")
MainEmbed(description="Testing description")

# ErrorEmbed & SuccessEmbed follow the same pattern

This new rework of embeds may cause unexpected behaviours in previous versions of disckit. Hence update your code accordingly if you're planning on updating to v0.9

The new features that have been added are-

  • Cooldown
  • Paginator
  • BaseView
  • BaseModal
  • BaseCog

Cooldowns-

The new cooldown feature allows you to place cooldown dynamically or statically based on per users, channels or guilds.

Example for adding cooldown statically & dynamically-

from disckit.utils.cooldown import CoolDown, CoolDownBucket
from discord import app_commands
from discord.ext import command


class DisckitTestCog(commands.Cog):
    def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot

    @app_commands.command()
    @CoolDown.cooldown(10, CoolDownBucket.CHANNEL)  # Adds a cooldown of 10 seconds for that channel
    async def cooldown_channel(self, interaction: Interaction) -> None:
        """Testing static cooldown for a channel for all users"""
        await interaction.response.send_message("This is to test cooldown on a channel for all users!")

    @app_commands.command()
    @CoolDown.cooldown(10, CoolDownBucket.USER)
    async def cooldown_user(self, interaction: Interaction) -> None:
        """Testing static cooldown for every user"""
        await interaction.response.send_message("This is to test cooldown per user!")

    @app_commands.command()
    async def dynamic_cooldown(self, interaction: Interaction) -> None:
        """Dynamically add cooldown to a specific user."""

        if interaction.user.id == 1022085572719808542:

            # Check if user of that ID is in cooldown or not
            allowed, cooldown_text = CoolDown.check(
                interaction, CoolDownBucket.USER
            )

            if not allowed:
                # If they are in cooldown, send an appropriate message
                await interaction.response.send_message(cooldown_text)
                return
            
            # If they are allowed, add the cooldown and continue the command
            CoolDown.add(25, interaction, CoolDownBucket.USER)

        await interaction.response.send_message(
            "Testing dynamic cooldowns"
        )

Paginators

Paginators allow users to view multiple "pages" of data within discord in a simple manner. The implementation allows it to be integrated to your bot with minimal code. You can paginate over strings or embeds. A small examples-

    @app_commands.command()
    async def pages(self, interaction: Interaction) -> None:
        """A test command for the custom disckit paginator"""

        await interaction.response.defer()

        home_page = MainEmbed("THIS IS HOME PAGE")

        pages = [
            MainEmbed("Page 1: Welcome to the paginator!"),
            SuccessEmbed(
                "Title 2", "Page 2: Here's some more content."
            ),
            MainEmbed("Page 3: Did you know this is a test?"),
            MainEmbed("Title 4", "Page 4: Almost halfway there!"),
            ErrorEmbed("Page 5: This is the fifth page."),
            "Some regular strings too.",
            "This is the second last page.",
            "This is the last page!"
        ]

        paginator = Paginator(
            interaction=interaction,
            pages=pages,
            home_page=home_page,
        )
        await paginator.start()

BaseView & BaseModal

The custom ui elements: BaseView & BaseModal extend discord.ui.View & discord.ui.Modal respectively while adding some additional features to them.

BaseView has some extra parameters which it can accept: disable_on_timeout & stop_on_timeout.

  • disable_on_timeout : This parameter controls weather to disable all children / items of a view once it times out.
  • stop_on_timeout : This parameter stops the view from listening to any further events associated to it once it times out.

Both BaseView & BaseModal have an error handler attached to them which is only enabled if disckit.UtilConfig.BUG_REPORT_CHANNEL attribute is defined.

BaseCog

BaseCog is just like a regular cog but it comes along with some basic logging which is executed on cog_load & cog_unload.

More

Other than these additions, the library is now finally properly typed and completely tested. If you do find any issues or errors, please make an issue or PR regarding it.

🦈

Full Changelog: v0.8...v0.9