Skip to content

An extension library for interactions.py improving component callbacks with persistence.

License

Notifications You must be signed in to change notification settings

SpyPlayer09/persistence

 
 

Repository files navigation

Persistence

PyPI - Downloads

An extension for interactions.py that dynamically places and returns objects in and from Discord's custom_ids so you don't have to. Check the wiki to learn how to use it!

How it works

The most popular interactions.py extension, Wait-For is an easy and effective way to simplify complex component chains by preserving the objects used during interaction. However, this means that any components created before the bot restarts become unresponsive. This could be solved by saving all previous needed interaction details to the disk, but that may not be an ideal solution for everyone. Luckily, there is another option.

The solution

The solution, originally conceived and executed by Toricane, was to place information in Discord's custom_ids. In the vanilla library, this requires some on_component or on_modal logic. Enhanced simplifies this by adding startswith and regex args to the bot.component and bot.modal decorators. However, even this is more complicated than necessary.

Further abstraction

Interactions-Persistence further simplifies placing objects in custom_ids using the json and allowing str, int, float, dict and list. The extension also encrypts custom_ids so it isn't obvious what they are doing. Using this ext is not only incredibly simple, but also reliable and lightweight. Taking a similar approach to Enhanced, Persistence uses on_component and on_modal listeners to identify and properly call persistent decorators.

This is a finished project, but it is being maintained and could accept new features. If you feel like you could contribute, please make an issue first. Thanks.

Enjoy!

About

An extension library for interactions.py improving component callbacks with persistence.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%