Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
/ cordcutter Public archive

The circuit breaker design pattern for discord.py application commands

License

Notifications You must be signed in to change notification settings

LunarsDev/cordcutter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔌 Cordcutter

❗ This is a fork of a similar extension for Nextcord by teaishealthy

Cordcutter is a discord.py extension that implements the circuit breaker design pattern for application commands.

Cordcutter works by watching for errors in your application commands and once the error threshold is reached (breaker tripped), it will disable the command for a set period of time. Once the cool-down period is over, the command will be re-enabled (breaker reset).

Cordcutter currently does not implement an semi-stable circuit breaker (half-open / half-tripped state), but this is a planned feature.

For more information on the circuit breaker design pattern, see this wikipedia article.

Installation

Cordcutter is currently in development and is not yet available on PyPI. You can install it from Git using pip:

python -m pip install git+https://github.com/LunarsDev/cordcutter.git

Usage

Simply import the Cordcutter class from cordcutter and pass your app_commands.CommandTree instance to it.

from cordcutter import Cordcutter
# <snip>
# tree: app_commands.CommandTree =...
cordcutter = Cordcutter(tree)

And set a callback for the breaker

import discord

@cordcutter.on_tripped_call
async def trip_callback(interaction: discord.Interaction):
    ...

Configuration

You can configure when the breaker trips and how long it stays tripped by passing the threshold and reset_after parameters to the Cordcutter constructor:

Cordcutter(
    tree,
    threshold = 3,
    reset_after = timedelta(minutes=5)
)

See the example.py file for more.

About

The circuit breaker design pattern for discord.py application commands

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages