[commands] Add Command.parents
Make command.root_parent use new command.parents property
This commit is contained in:
parent
bb3ebc0ebc
commit
bbf9a42f87
@ -503,6 +503,27 @@ class Command(_BaseCommand):
|
|||||||
|
|
||||||
return ' '.join(reversed(entries))
|
return ' '.join(reversed(entries))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parents(self):
|
||||||
|
"""Retrieves the parents of this command.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.0
|
||||||
|
|
||||||
|
If the command has no parents then it returns an empty :class:`list`.
|
||||||
|
|
||||||
|
For example in commands ``?a b c test``,
|
||||||
|
the parents are ``[c, b, a]``.
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
entries = []
|
||||||
|
command = self
|
||||||
|
while command.parent is not None:
|
||||||
|
command = command.parent
|
||||||
|
entries.append(command)
|
||||||
|
|
||||||
|
return entries
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def root_parent(self):
|
def root_parent(self):
|
||||||
"""Retrieves the root parent of this command.
|
"""Retrieves the root parent of this command.
|
||||||
@ -512,16 +533,9 @@ class Command(_BaseCommand):
|
|||||||
For example in commands ``?a b c test``, the root parent is
|
For example in commands ``?a b c test``, the root parent is
|
||||||
``a``.
|
``a``.
|
||||||
"""
|
"""
|
||||||
entries = []
|
if not self.parent:
|
||||||
command = self
|
|
||||||
while command.parent is not None:
|
|
||||||
command = command.parent
|
|
||||||
entries.append(command)
|
|
||||||
|
|
||||||
if len(entries) == 0:
|
|
||||||
return None
|
return None
|
||||||
|
return self.parents[-1]
|
||||||
return entries[-1]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def qualified_name(self):
|
def qualified_name(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user