def _make_command_requirements(command):
requirements = []
# All commands in this cog are owner-only anyway.
if command.cog_name == 'Owner':
requirements.append('**Bot Owner only**')
def make_pretty(p):
return p.replace('_', ' ').title().replace('Guild', 'Server')
for check in command.checks:
name = getattr(check, '__qualname__', '')
if name.startswith('is_owner'):
# the bot owner line must come above every other line, for emphasis.
requirements.insert(0, '**Bot Owner only**')
elif name.startswith('has_permissions'):
permissions = inspect.getclosurevars(check).nonlocals['perms']
pretty_perms = [make_pretty(k) if v else f'~~{make_pretty(k)}~~'
for k, v in permissions.items()]
perm_names = ', '.join(pretty_perms)
requirements.append(f'{perm_names} permission{"s" * (len(pretty_perms) != 1)}')
return '\n'.join(requirements)
评论列表
文章目录