Skip to content

Commit

Permalink
feat: merge error handlers & raise_command_errors config var
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyu committed Oct 5, 2023
1 parent ca8a87b commit 6771e10
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions bot/cogs/osu.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import logging
import humanize
import math
import time
import humanize
import logging
import yaml

from datetime import datetime
from discord.ext import commands
from string import Template
from discord import Embed
from discord.ext import commands
from bot.bot import config
from helpers.converters import ArgumentConverter
from utils.api import *
from utils.enums import GameModes, Grades, Mods, filter_invalid_combos
from utils.db import users
from string import Template

from utils.enums import GameModes, Grades, Mods, filter_invalid_combos

DEBUG: bool = config.get("debug")
domain = config.get("domain")

with open("templates.yml", "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -48,7 +46,7 @@ def construct_avatar_url(player_id):


async def get_username_and_mode(
ctx, username: str = None, mode: GameModes = GameModes.STANDARD
ctx, username: str = None, mode: GameModes = GameModes.STANDARD
):
"""
Returns a tuple containing the username and GameMode
Expand Down Expand Up @@ -89,7 +87,7 @@ async def setuser(self, ctx, *, username):

@commands.command()
async def rs(
self, ctx, username: str = None, mode: ArgumentConverter = GameModes.STANDARD
self, ctx, username: str = None, mode: ArgumentConverter = GameModes.STANDARD
):
mode: GameModes

Expand Down Expand Up @@ -160,10 +158,6 @@ async def rs(

return await ctx.send(embed=embed)

@rs.error
async def rs_error(self, ctx, error):
await ctx.send(error.__cause__ or error)

@commands.command(
aliases=["mania", "ctb", "taiko", "rx", "ap", "std", "taikorx", "ctbrx"]
)
Expand Down Expand Up @@ -253,10 +247,6 @@ def get_level(score):

return await ctx.send(embed=embed)

@osu.error
async def osu_error(self, ctx, error):
return await ctx.send(error.__cause__ or error)

@commands.command(aliases=["lb"])
async def leaderboard(self, ctx, *, mode: ArgumentConverter = GameModes.STANDARD):
mode: GameModes
Expand Down Expand Up @@ -289,10 +279,6 @@ async def leaderboard(self, ctx, *, mode: ArgumentConverter = GameModes.STANDARD

await ctx.send(embed=embed)

@leaderboard.error
async def leaderboard_error(self, ctx, error):
return await ctx.send(error.__cause__ or error)

@commands.command()
async def stats(self, ctx):
try:
Expand Down Expand Up @@ -411,9 +397,10 @@ async def osutop(self, ctx, username: str = None):

await ctx.send(embed=embed)

@osutop.error
async def top_error(self, ctx, error):
async def cog_command_error(self, ctx, error: Exception) -> None:
await ctx.send(error.__cause__ or error)
if config.get("raise_command_errors", False):
raise error


async def setup(bot):
Expand Down

0 comments on commit 6771e10

Please sign in to comment.