Skip to content

Commit

Permalink
feat: add slash command mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Jul 28, 2022
1 parent 2df688b commit a87bd19
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"</{self.qualified_name}:{self.id}>"

@property
def default_member_permissions(self) -> Optional[Permissions]:
"""Optional[:class:`.Permissions`]: The default required member permissions for this command.
Expand Down
45 changes: 45 additions & 0 deletions disnake/ext/commands/slash_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"</{self.qualified_name}:{self.id}>"

# todo: refactor this class to make this not optional
@property
def parent(self) -> Optional[InvokableSlashCommand]:
"""Optional[:class:`InvokableSlashCommand`] The parent of this SubCommandGroup.
Expand All @@ -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,
Expand Down Expand Up @@ -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"</{self.qualified_name}:{self.id}>"

@property
def parent(self) -> Optional[Union[InvokableSlashCommand, SubCommandGroup]]:
"""Optional[Union[:class:`InvokableSlashCommand`, :class:`SubCommandGroup`]]: The parent of this subcommand.
Expand All @@ -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]:
Expand Down

0 comments on commit a87bd19

Please sign in to comment.