mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
[commands] Add Command.qualified_name to get the full command name.
This also sets `__str__` to do the same thing.
This commit is contained in:
parent
37dfe38af5
commit
661645ac97
@ -306,6 +306,38 @@ class Command:
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@property
|
||||||
|
def full_parent_name(self):
|
||||||
|
"""Retrieves the fully qualified parent command name.
|
||||||
|
|
||||||
|
This the base command name required to execute it. For example,
|
||||||
|
in ``?one two three`` the parent name would be ``one two``.
|
||||||
|
"""
|
||||||
|
entries = []
|
||||||
|
command = self
|
||||||
|
while command.parent is not None:
|
||||||
|
command = command.parent
|
||||||
|
entries.append(command.name)
|
||||||
|
|
||||||
|
return ' '.join(reversed(entries))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def qualified_name(self):
|
||||||
|
"""Retrieves the fully qualified command name.
|
||||||
|
|
||||||
|
This is the full parent name with the command name as well.
|
||||||
|
For example, in ``?one two three`` the qualified name would be
|
||||||
|
``one two three``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
parent = self.full_parent_name
|
||||||
|
if parent:
|
||||||
|
return parent + ' ' + self.name
|
||||||
|
else:
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.qualified_name
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _parse_arguments(self, ctx):
|
def _parse_arguments(self, ctx):
|
||||||
|
@ -117,32 +117,20 @@ class HelpFormatter:
|
|||||||
# odd one.
|
# odd one.
|
||||||
return self.context.prefix.replace(user.mention, '@' + user.name)
|
return self.context.prefix.replace(user.mention, '@' + user.name)
|
||||||
|
|
||||||
def get_qualified_command_name(self):
|
|
||||||
"""Retrieves the fully qualified command name, i.e. the base command name
|
|
||||||
required to execute it. This does not contain the command name itself.
|
|
||||||
"""
|
|
||||||
entries = []
|
|
||||||
command = self.command
|
|
||||||
while command.parent is not None:
|
|
||||||
command = command.parent
|
|
||||||
entries.append(command.name)
|
|
||||||
|
|
||||||
return ' '.join(reversed(entries))
|
|
||||||
|
|
||||||
def get_command_signature(self):
|
def get_command_signature(self):
|
||||||
"""Retrieves the signature portion of the help page."""
|
"""Retrieves the signature portion of the help page."""
|
||||||
result = []
|
result = []
|
||||||
prefix = self.clean_prefix
|
prefix = self.clean_prefix
|
||||||
qualified = self.get_qualified_command_name()
|
|
||||||
cmd = self.command
|
cmd = self.command
|
||||||
|
parent = cmd.full_parent_name
|
||||||
if len(cmd.aliases) > 0:
|
if len(cmd.aliases) > 0:
|
||||||
aliases = '|'.join(cmd.aliases)
|
aliases = '|'.join(cmd.aliases)
|
||||||
fmt = '{0}[{1.name}|{2}]'
|
fmt = '{0}[{1.name}|{2}]'
|
||||||
if qualified:
|
if parent:
|
||||||
fmt = '{0}{3} [{1.name}|{2}]'
|
fmt = '{0}{3} [{1.name}|{2}]'
|
||||||
result.append(fmt.format(prefix, cmd, aliases, qualified))
|
result.append(fmt.format(prefix, cmd, aliases, parent))
|
||||||
else:
|
else:
|
||||||
name = prefix + cmd.name if not qualified else prefix + qualified + ' ' + cmd.name
|
name = prefix + cmd.name if not parent else prefix + parent + ' ' + cmd.name
|
||||||
result.append(name)
|
result.append(name)
|
||||||
|
|
||||||
params = cmd.clean_params
|
params = cmd.clean_params
|
||||||
|
Loading…
x
Reference in New Issue
Block a user