2016-12-02 17:01:53 +13:00
|
|
|
def get_all_commands(bot):
|
|
|
|
# First lets create a set of all the parent names
|
|
|
|
parent_command_names = set(cmd.qualified_name for cmd in bot.commands)
|
|
|
|
all_commands = []
|
|
|
|
|
|
|
|
# Now lets loop through and get all the child commands for each command
|
|
|
|
# Only the command itself will be yielded if there are no children
|
|
|
|
for cmd_name in parent_command_names:
|
|
|
|
cmd = bot.commands.get(cmd_name)
|
|
|
|
for child_cmd in _get_all_commands(cmd):
|
|
|
|
all_commands.append(child_cmd)
|
|
|
|
|
|
|
|
return all_commands
|
|
|
|
|
|
|
|
def _get_all_commands(command):
|
|
|
|
yield command.qualified_name
|
|
|
|
try:
|
|
|
|
for cmd in command.commands:
|
2016-12-02 17:02:42 +13:00
|
|
|
yield from _get_all_commands(cmd)
|
2016-12-02 17:01:53 +13:00
|
|
|
except AttributeError:
|
|
|
|
pass
|