Skip to content

Commit

Permalink
cleanup the CommandErrorHandler cog
Browse files Browse the repository at this point in the history
  • Loading branch information
shtlrs committed Mar 18, 2024
1 parent 579ffbf commit fd6490c
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions bot/exts/core/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,17 @@
import random
from collections.abc import Iterable

from discord import Embed, Message
from discord.ext import commands
from pydis_core.utils.logging import get_logger

from bot.bot import Bot
from bot.constants import Colours, ERROR_REPLIES

log = get_logger(__name__)


DELETE_DELAY = 10
QUESTION_MARK_ICON = "https://cdn.discordapp.com/emojis/512367613339369475.png"


class CommandErrorHandler(commands.Cog):
"""A error handler for the PythonDiscord server."""

def __init__(self, bot: Bot):
self.bot = bot

@staticmethod
def revert_cooldown_counter(command: commands.Command, message: Message) -> None:
"""Undoes the last cooldown counter for user-error cases."""
if command._buckets.valid:
bucket = command._buckets.get_bucket(message)
bucket._tokens = min(bucket.rate, bucket._tokens + 1)
log.debug("Cooldown counter reverted as the command was not used correctly.")

@staticmethod
def error_embed(message: str, title: Iterable | str = ERROR_REPLIES) -> Embed:
"""Build a basic embed with red colour and either a random error title or a title provided."""
embed = Embed(colour=Colours.soft_red)
if isinstance(title, str):
embed.title = title
else:
embed.title = random.choice(title)
embed.description = message
return embed

@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
"""Activates when a command raises an error."""
Expand Down

0 comments on commit fd6490c

Please sign in to comment.