def filter_command_list(self, command):
"""Returns a filtered list of commands based on the two attributes
provided, :attr:`show_check_failure` and :attr:`show_hidden`. Also
filters based on if :meth:`is_cog` is valid.
Returns
--------
iterable
An iterable with the filter being applied. The resulting value is
a (key, value) tuple of the command name and the command itself.
"""
def sane_no_suspension_point_predicate(tup):
cmd = tup[1]
if self.is_cog(command):
# filter commands that don't exist to this cog.
if cmd.instance is not command:
return False
if cmd.hidden and not self.show_hidden:
return False
return True
async def predicate(tup):
if sane_no_suspension_point_predicate(tup) is False:
return False
cmd = tup[1]
try:
return await cmd.can_run(self.context)
except commands.CommandError:
return False
iterator = command.all_commands.items() if not self.is_cog(command) else self.context.bot.all_commands.items()
if self.show_check_failure:
return filter(sane_no_suspension_point_predicate, iterator)
# Gotta run every check and verify it
ret = []
for elem in iterator:
valid = await predicate(elem)
if valid:
ret.append(elem)
return ret
评论列表
文章目录