Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
🐛 Bugfix for no argument commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurdw committed Sep 9, 2021
1 parent 572bd1a commit cd7b531
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
10 changes: 8 additions & 2 deletions pincer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from .objects import User
from .objects.interaction_base import MessageInteractionCallbackType
from .objects.interactions import Interaction, InteractionCallbackDataFlags
from .utils import get_index, should_pass_cls, Coro
from .utils import get_index, should_pass_cls, Coro, MISSING
from .utils.extraction import get_params

_log = logging.getLogger(__package__)
Expand Down Expand Up @@ -389,7 +389,13 @@ async def on_interaction_middleware(self, payload: GatewayDispatch):

if command:
defaults = {param: None for param in get_params(command.call)}
params = {opt.name: opt.value for opt in interaction.data.options}
params = {}

if interaction.data.options is not MISSING:
params = {
opt.name: opt.value for opt in interaction.data.options
}

kwargs = {**defaults, **params}

if should_pass_cls(command.call):
Expand Down
8 changes: 5 additions & 3 deletions pincer/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
from . import __package__
from .exceptions import (
CommandIsNotCoroutine, CommandAlreadyRegistered, TooManyArguments,
InvalidArgumentAnnotation, CommandDescriptionTooLong, NotFoundError
InvalidArgumentAnnotation, CommandDescriptionTooLong
)
from .objects.application_command import (
AppCommand, AppCommandType, ClientCommandStructure,
AppCommandOption, AppCommandOptionType
)
from .utils import (
get_signature_and_params, get_index, should_pass_ctx, Coro, Snowflake, MISSING
get_signature_and_params, get_index, should_pass_ctx, Coro, Snowflake,
MISSING
)

_log = logging.getLogger(__package__)
Expand Down Expand Up @@ -214,7 +215,8 @@ def get_changes(
else:
options = local.options

if list(map(AppCommandOption.from_dict, options)) != api.options:
if api.options is not MISSING and list(
map(AppCommandOption.from_dict, options)) != api.options:
update["options"] = options

return update
Expand Down
6 changes: 6 additions & 0 deletions pincer/objects/application_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def __post_init__(self):
)
self.guild_id = convert(self.guild_id, Snowflake.from_string)

self.options = [] if self.options is MISSING else self.options

def __eq__(self, other: Union[AppCommand, ClientCommandStructure]):
if isinstance(other, ClientCommandStructure):
other = other.app
Expand All @@ -264,6 +266,10 @@ def __eq__(self, other: Union[AppCommand, ClientCommandStructure]):
for prop in self._eq_props
)

if (self.options is MISSING and other.options is not MISSING) or \
(self.options is not MISSING and other.options is MISSING):
return False

if is_equal and len(other.options) == len(self.options):
for idx, option in enumerate(other.options):
option_comp: Optional[AppCommandOption] = \
Expand Down

0 comments on commit cd7b531

Please sign in to comment.