From a87bd1933d3c3327df0026e96f8523dbab32a2bf Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Thu, 28 Jul 2022 02:50:37 -0400 Subject: [PATCH] feat: add slash command mentions --- disnake/ext/commands/base_core.py | 5 ++++ disnake/ext/commands/slash_core.py | 45 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/disnake/ext/commands/base_core.py b/disnake/ext/commands/base_core.py index c099bf8635..c65ee9b10b 100644 --- a/disnake/ext/commands/base_core.py +++ b/disnake/ext/commands/base_core.py @@ -249,6 +249,11 @@ def qualified_name(self) -> str: """ return self.name + @property + def mention(self) -> str: + # todo: add docs and make ID non-nullable + return f"" + @property def default_member_permissions(self) -> Optional[Permissions]: """Optional[:class:`.Permissions`]: The default required member permissions for this command. diff --git a/disnake/ext/commands/slash_core.py b/disnake/ext/commands/slash_core.py index 5c90ba5b13..d316d7e19b 100644 --- a/disnake/ext/commands/slash_core.py +++ b/disnake/ext/commands/slash_core.py @@ -192,6 +192,12 @@ def qualified_name(self) -> str: return self.name return f"{self._parent.qualified_name} {self.name}" + @property + def mention(self) -> str: + # todo: add docs and make ID non-nullable + return f"" + + # todo: refactor this class to make this not optional @property def parent(self) -> Optional[InvokableSlashCommand]: """Optional[:class:`InvokableSlashCommand`] The parent of this SubCommandGroup. @@ -200,6 +206,20 @@ def parent(self) -> Optional[InvokableSlashCommand]: """ return self._parent + @property + def parents( + self, + ) -> Tuple[InvokableSlashCommand]: + """Tuple[:class:`InvokableSlashCommand`]: Retrieves the parents of this command. + + If the command has no parents then it returns an empty :class:`tuple`. + + For example in commands ``/a b test``, the parents are ``(b, a)``. + + .. versionadded:: 2.6 + """ + return (self.parent,) # type: ignore + def sub_command( self, name: LocalizedOptional = None, @@ -329,6 +349,11 @@ def qualified_name(self) -> str: return self.name return f"{self._parent.qualified_name} {self.name}" + @property + def mention(self) -> str: + # todo: add docs and make ID non-nullable + return f"" + @property def parent(self) -> Optional[Union[InvokableSlashCommand, SubCommandGroup]]: """Optional[Union[:class:`InvokableSlashCommand`, :class:`SubCommandGroup`]]: The parent of this subcommand. @@ -338,6 +363,26 @@ def parent(self) -> Optional[Union[InvokableSlashCommand, SubCommandGroup]]: # todo: figure out when this can be optional or not, and try to make it non-optional for user-experience return self._parent + @property + def parents( + self, + ) -> Union[Tuple[InvokableSlashCommand], Tuple[SubCommandGroup, InvokableSlashCommand]]: + """Union[Tuple[:class:`InvokableSlashCommand`], Tuple[:class:`SubCommandGroup`, :class:`InvokableSlashCommand`]]: Retrieves the parents of this command. + + If the command has no parents then it returns an empty :class:`tuple`. + + For example in commands ``/a b test``, the parents are ``(b, a)``. + + .. versionadded:: 2.6 + """ + entries = [] + command = self + while command.parent is not None: # type: ignore + command = command.parent # type: ignore + entries.append(command) + + return tuple(entries) + async def _call_autocompleter( self, param: str, inter: ApplicationCommandInteraction, user_input: str ) -> Optional[Choices]: