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

Latest commit

 

History

History
53 lines (37 loc) · 1.77 KB

README.md

File metadata and controls

53 lines (37 loc) · 1.77 KB

🔌 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.