From 689e9bf7652f3393cf3041ea3d6462484fdf6ac8 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:30:15 +0100 Subject: [PATCH] fix: Linting --- discord_tools/app_commands/checks.py | 9 ++++++--- discord_tools/app_commands/transformers.py | 11 ++++++----- examples/app_commands/max_concurrency.py | 20 ++++++++++++++------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/discord_tools/app_commands/checks.py b/discord_tools/app_commands/checks.py index 6d814e5..01e7295 100644 --- a/discord_tools/app_commands/checks.py +++ b/discord_tools/app_commands/checks.py @@ -101,9 +101,9 @@ def max_concurrency(number: int, per: BucketType = BucketType.default): def decorator(func): async def predicate(interaction: Interaction[Any]) -> bool: if interaction.command is None: - obj = getattr(func, '__discord_app_commands_max_concurrency__', None) + obj = getattr(func, "__discord_app_commands_max_concurrency__", None) else: - obj = interaction.command.extras.get('__max_concurrency__') + obj = interaction.command.extras.get("__max_concurrency__") if not isinstance(obj, MaxConcurrency): return True @@ -117,6 +117,9 @@ async def predicate(interaction: Interaction[Any]) -> bool: if isinstance(func, (Command, Group)): func.extras["__max_concurrency__"] = MaxConcurrency(number, per=per) else: - func.__discord_app_commands_max_concurrency__ = MaxConcurrency(number, per=per) + func.__discord_app_commands_max_concurrency__ = MaxConcurrency( + number, per=per + ) return check(predicate)(func) + return decorator diff --git a/discord_tools/app_commands/transformers.py b/discord_tools/app_commands/transformers.py index e1c3597..58b5934 100644 --- a/discord_tools/app_commands/transformers.py +++ b/discord_tools/app_commands/transformers.py @@ -25,7 +25,7 @@ from __future__ import annotations from functools import partial -from typing import TypeVar, Generic, Any +from typing import TypeVar, Any import discord from discord.app_commands import Transformer @@ -52,16 +52,17 @@ class Greedy(Transformer): .. versionadded:: 1.0 """ - def __init__(self, converter: T) -> None: # pyright: ignore[reportInvalidTypeVarUse] + def __init__( + self, + converter: T, # pyright: ignore[reportInvalidTypeVarUse] + ) -> None: if converter not in CONVERTER_MAPPING and not is_generic_type(converter): raise ValueError( f"Cannot set the Greedy converter to {converter.__class__.__name__}" ) self._converter: T = converter - async def transform( - self, interaction: discord.Interaction, argument: str - ) -> Any: + async def transform(self, interaction: discord.Interaction, argument: str) -> Any: ctx = await Context.from_interaction(interaction) # type: ignore assert ctx.current_parameter is not None view = ctx.view.__class__(argument) diff --git a/examples/app_commands/max_concurrency.py b/examples/app_commands/max_concurrency.py index 8f5d195..c4f5193 100644 --- a/examples/app_commands/max_concurrency.py +++ b/examples/app_commands/max_concurrency.py @@ -20,18 +20,26 @@ # we define a command @tree.command() # and we apply our max_concurrency decorator, limiting to 1 usage per user -@discord_tools.app_commands.max_concurrency(1, per=discord_tools.app_commands.BucketType.user) +@discord_tools.app_commands.max_concurrency( + 1, per=discord_tools.app_commands.BucketType.user +) async def some_long_operation(interaction: discord.Interaction) -> None: await interaction.response.defer() # we defer so we can respond in more than 3 seconds - await asyncio.sleep(10) # simulate some long operation: db calls, web requests, etc. - await interaction.followup.send('Completed!') # we tell the user the operation has finished + await asyncio.sleep( + 10 + ) # simulate some long operation: db calls, web requests, etc. + await interaction.followup.send( + "Completed!" + ) # we tell the user the operation has finished # we now define the error handling for our command # this can be done in different ways, but in this case, we will use # the @.error decorator @some_long_operation.error -async def some_long_operation_error(interaction: discord.Interaction, error: discord.app_commands.AppCommandError): +async def some_long_operation_error( + interaction: discord.Interaction, error: discord.app_commands.AppCommandError +): # we now check if our error is the one that max_concurrency raises if isinstance(error, discord_tools.app_commands.MaxConcurrencyReached): # now we tell the user that they have reached maximum concurrency in X bucket @@ -39,13 +47,13 @@ async def some_long_operation_error(interaction: discord.Interaction, error: dis # if the interaction has not been responded, we respond to it if not interaction.response.is_done(): await interaction.response.send_message( - f'You have reached the {error.number} per {error.per.name} command usage', + f"You have reached the {error.number} per {error.per.name} command usage", ephemeral=True, ) # if it has, then we send a followup else: await interaction.followup.send( - f'You have reached the {error.number} per {error.per.name} command usage', + f"You have reached the {error.number} per {error.per.name} command usage", ephemeral=True, ) else: