Fix code style issues with Black
This commit is contained in:
@@ -39,10 +39,10 @@ if TYPE_CHECKING:
|
||||
from .context import Context
|
||||
|
||||
__all__ = (
|
||||
'Paginator',
|
||||
'HelpCommand',
|
||||
'DefaultHelpCommand',
|
||||
'MinimalHelpCommand',
|
||||
"Paginator",
|
||||
"HelpCommand",
|
||||
"DefaultHelpCommand",
|
||||
"MinimalHelpCommand",
|
||||
)
|
||||
|
||||
# help -> shows info of bot on top/bottom and lists subcommands
|
||||
@@ -89,7 +89,7 @@ class Paginator:
|
||||
.. versionadded:: 1.7
|
||||
"""
|
||||
|
||||
def __init__(self, prefix='```', suffix='```', max_size=2000, linesep='\n'):
|
||||
def __init__(self, prefix="```", suffix="```", max_size=2000, linesep="\n"):
|
||||
self.prefix = prefix
|
||||
self.suffix = suffix
|
||||
self.max_size = max_size
|
||||
@@ -118,7 +118,7 @@ class Paginator:
|
||||
def _linesep_len(self):
|
||||
return len(self.linesep)
|
||||
|
||||
def add_line(self, line='', *, empty=False):
|
||||
def add_line(self, line="", *, empty=False):
|
||||
"""Adds a line to the current page.
|
||||
|
||||
If the line exceeds the :attr:`max_size` then an exception
|
||||
@@ -138,7 +138,7 @@ class Paginator:
|
||||
"""
|
||||
max_page_size = self.max_size - self._prefix_len - self._suffix_len - 2 * self._linesep_len
|
||||
if len(line) > max_page_size:
|
||||
raise RuntimeError(f'Line exceeds maximum page size {max_page_size}')
|
||||
raise RuntimeError(f"Line exceeds maximum page size {max_page_size}")
|
||||
|
||||
if self._count + len(line) + self._linesep_len > self.max_size - self._suffix_len:
|
||||
self.close_page()
|
||||
@@ -147,7 +147,7 @@ class Paginator:
|
||||
self._current_page.append(line)
|
||||
|
||||
if empty:
|
||||
self._current_page.append('')
|
||||
self._current_page.append("")
|
||||
self._count += self._linesep_len
|
||||
|
||||
def close_page(self):
|
||||
@@ -176,7 +176,7 @@ class Paginator:
|
||||
return self._pages
|
||||
|
||||
def __repr__(self):
|
||||
fmt = '<Paginator prefix: {0.prefix!r} suffix: {0.suffix!r} linesep: {0.linesep!r} max_size: {0.max_size} count: {0._count}>'
|
||||
fmt = "<Paginator prefix: {0.prefix!r} suffix: {0.suffix!r} linesep: {0.linesep!r} max_size: {0.max_size} count: {0._count}>"
|
||||
return fmt.format(self)
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ class _HelpCommandImpl(Command):
|
||||
self.callback = injected.command_callback
|
||||
|
||||
on_error = injected.on_help_command_error
|
||||
if not hasattr(on_error, '__help_command_not_overriden__'):
|
||||
if not hasattr(on_error, "__help_command_not_overriden__"):
|
||||
if self.cog is not None:
|
||||
self.on_error = self._on_error_cog_implementation
|
||||
else:
|
||||
@@ -224,7 +224,7 @@ class _HelpCommandImpl(Command):
|
||||
try:
|
||||
del result[next(iter(result))]
|
||||
except StopIteration:
|
||||
raise ValueError('Missing context parameter') from None
|
||||
raise ValueError("Missing context parameter") from None
|
||||
else:
|
||||
return result
|
||||
|
||||
@@ -296,13 +296,13 @@ class HelpCommand:
|
||||
"""
|
||||
|
||||
MENTION_TRANSFORMS = {
|
||||
'@everyone': '@\u200beveryone',
|
||||
'@here': '@\u200bhere',
|
||||
r'<@!?[0-9]{17,22}>': '@deleted-user',
|
||||
r'<@&[0-9]{17,22}>': '@deleted-role',
|
||||
"@everyone": "@\u200beveryone",
|
||||
"@here": "@\u200bhere",
|
||||
r"<@!?[0-9]{17,22}>": "@deleted-user",
|
||||
r"<@&[0-9]{17,22}>": "@deleted-role",
|
||||
}
|
||||
|
||||
MENTION_PATTERN = re.compile('|'.join(MENTION_TRANSFORMS.keys()))
|
||||
MENTION_PATTERN = re.compile("|".join(MENTION_TRANSFORMS.keys()))
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
# To prevent race conditions of a single instance while also allowing
|
||||
@@ -321,11 +321,11 @@ class HelpCommand:
|
||||
return self
|
||||
|
||||
def __init__(self, **options):
|
||||
self.show_hidden = options.pop('show_hidden', False)
|
||||
self.verify_checks = options.pop('verify_checks', True)
|
||||
self.command_attrs = attrs = options.pop('command_attrs', {})
|
||||
attrs.setdefault('name', 'help')
|
||||
attrs.setdefault('help', 'Shows this message')
|
||||
self.show_hidden = options.pop("show_hidden", False)
|
||||
self.verify_checks = options.pop("verify_checks", True)
|
||||
self.command_attrs = attrs = options.pop("command_attrs", {})
|
||||
attrs.setdefault("name", "help")
|
||||
attrs.setdefault("help", "Shows this message")
|
||||
self.context: Context = discord.utils.MISSING
|
||||
self._command_impl = _HelpCommandImpl(self, **self.command_attrs)
|
||||
|
||||
@@ -422,20 +422,20 @@ class HelpCommand:
|
||||
if not parent.signature or parent.invoke_without_command:
|
||||
entries.append(parent.name)
|
||||
else:
|
||||
entries.append(parent.name + ' ' + parent.signature)
|
||||
entries.append(parent.name + " " + parent.signature)
|
||||
parent = parent.parent
|
||||
parent_sig = ' '.join(reversed(entries))
|
||||
parent_sig = " ".join(reversed(entries))
|
||||
|
||||
if len(command.aliases) > 0:
|
||||
aliases = '|'.join(command.aliases)
|
||||
fmt = f'[{command.name}|{aliases}]'
|
||||
aliases = "|".join(command.aliases)
|
||||
fmt = f"[{command.name}|{aliases}]"
|
||||
if parent_sig:
|
||||
fmt = parent_sig + ' ' + fmt
|
||||
fmt = parent_sig + " " + fmt
|
||||
alias = fmt
|
||||
else:
|
||||
alias = command.name if not parent_sig else parent_sig + ' ' + command.name
|
||||
alias = command.name if not parent_sig else parent_sig + " " + command.name
|
||||
|
||||
return f'{self.context.clean_prefix}{alias} {command.signature}'
|
||||
return f"{self.context.clean_prefix}{alias} {command.signature}"
|
||||
|
||||
def remove_mentions(self, string):
|
||||
"""Removes mentions from the string to prevent abuse.
|
||||
@@ -449,7 +449,7 @@ class HelpCommand:
|
||||
"""
|
||||
|
||||
def replace(obj, *, transforms=self.MENTION_TRANSFORMS):
|
||||
return transforms.get(obj.group(0), '@invalid')
|
||||
return transforms.get(obj.group(0), "@invalid")
|
||||
|
||||
return self.MENTION_PATTERN.sub(replace, string)
|
||||
|
||||
@@ -846,7 +846,7 @@ class HelpCommand:
|
||||
# Since we want to have detailed errors when someone
|
||||
# passes an invalid subcommand, we need to walk through
|
||||
# the command group chain ourselves.
|
||||
keys = command.split(' ')
|
||||
keys = command.split(" ")
|
||||
cmd = bot.all_commands.get(keys[0])
|
||||
if cmd is None:
|
||||
string = await maybe_coro(self.command_not_found, self.remove_mentions(keys[0]))
|
||||
@@ -907,14 +907,14 @@ class DefaultHelpCommand(HelpCommand):
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
self.width = options.pop('width', 80)
|
||||
self.indent = options.pop('indent', 2)
|
||||
self.sort_commands = options.pop('sort_commands', True)
|
||||
self.dm_help = options.pop('dm_help', False)
|
||||
self.dm_help_threshold = options.pop('dm_help_threshold', 1000)
|
||||
self.commands_heading = options.pop('commands_heading', "Commands:")
|
||||
self.no_category = options.pop('no_category', 'No Category')
|
||||
self.paginator = options.pop('paginator', None)
|
||||
self.width = options.pop("width", 80)
|
||||
self.indent = options.pop("indent", 2)
|
||||
self.sort_commands = options.pop("sort_commands", True)
|
||||
self.dm_help = options.pop("dm_help", False)
|
||||
self.dm_help_threshold = options.pop("dm_help_threshold", 1000)
|
||||
self.commands_heading = options.pop("commands_heading", "Commands:")
|
||||
self.no_category = options.pop("no_category", "No Category")
|
||||
self.paginator = options.pop("paginator", None)
|
||||
|
||||
if self.paginator is None:
|
||||
self.paginator = Paginator()
|
||||
@@ -924,7 +924,7 @@ class DefaultHelpCommand(HelpCommand):
|
||||
def shorten_text(self, text):
|
||||
""":class:`str`: Shortens text to fit into the :attr:`width`."""
|
||||
if len(text) > self.width:
|
||||
return text[:self.width - 3].rstrip() + '...'
|
||||
return text[: self.width - 3].rstrip() + "..."
|
||||
return text
|
||||
|
||||
def get_ending_note(self):
|
||||
@@ -1021,11 +1021,11 @@ class DefaultHelpCommand(HelpCommand):
|
||||
# <description> portion
|
||||
self.paginator.add_line(bot.description, empty=True)
|
||||
|
||||
no_category = f'\u200b{self.no_category}:'
|
||||
no_category = f"\u200b{self.no_category}:"
|
||||
|
||||
def get_category(command, *, no_category=no_category):
|
||||
cog = command.cog
|
||||
return cog.qualified_name + ':' if cog is not None else no_category
|
||||
return cog.qualified_name + ":" if cog is not None else no_category
|
||||
|
||||
filtered = await self.filter_commands(bot.commands, sort=True, key=get_category)
|
||||
max_size = self.get_max_size(filtered)
|
||||
@@ -1110,13 +1110,13 @@ class MinimalHelpCommand(HelpCommand):
|
||||
"""
|
||||
|
||||
def __init__(self, **options):
|
||||
self.sort_commands = options.pop('sort_commands', True)
|
||||
self.commands_heading = options.pop('commands_heading', "Commands")
|
||||
self.dm_help = options.pop('dm_help', False)
|
||||
self.dm_help_threshold = options.pop('dm_help_threshold', 1000)
|
||||
self.aliases_heading = options.pop('aliases_heading', "Aliases:")
|
||||
self.no_category = options.pop('no_category', 'No Category')
|
||||
self.paginator = options.pop('paginator', None)
|
||||
self.sort_commands = options.pop("sort_commands", True)
|
||||
self.commands_heading = options.pop("commands_heading", "Commands")
|
||||
self.dm_help = options.pop("dm_help", False)
|
||||
self.dm_help_threshold = options.pop("dm_help_threshold", 1000)
|
||||
self.aliases_heading = options.pop("aliases_heading", "Aliases:")
|
||||
self.no_category = options.pop("no_category", "No Category")
|
||||
self.paginator = options.pop("paginator", None)
|
||||
|
||||
if self.paginator is None:
|
||||
self.paginator = Paginator(suffix=None, prefix=None)
|
||||
@@ -1149,7 +1149,7 @@ class MinimalHelpCommand(HelpCommand):
|
||||
)
|
||||
|
||||
def get_command_signature(self, command):
|
||||
return f'{self.context.clean_prefix}{command.qualified_name} {command.signature}'
|
||||
return f"{self.context.clean_prefix}{command.qualified_name} {command.signature}"
|
||||
|
||||
def get_ending_note(self):
|
||||
"""Return the help command's ending note. This is mainly useful to override for i18n purposes.
|
||||
@@ -1180,8 +1180,8 @@ class MinimalHelpCommand(HelpCommand):
|
||||
"""
|
||||
if commands:
|
||||
# U+2002 Middle Dot
|
||||
joined = '\u2002'.join(c.name for c in commands)
|
||||
self.paginator.add_line(f'__**{heading}**__')
|
||||
joined = "\u2002".join(c.name for c in commands)
|
||||
self.paginator.add_line(f"__**{heading}**__")
|
||||
self.paginator.add_line(joined)
|
||||
|
||||
def add_subcommand_formatting(self, command):
|
||||
@@ -1197,7 +1197,7 @@ class MinimalHelpCommand(HelpCommand):
|
||||
command: :class:`Command`
|
||||
The command to show information of.
|
||||
"""
|
||||
fmt = '{0}{1} \N{EN DASH} {2}' if command.short_doc else '{0}{1}'
|
||||
fmt = "{0}{1} \N{EN DASH} {2}" if command.short_doc else "{0}{1}"
|
||||
self.paginator.add_line(fmt.format(self.context.clean_prefix, command.qualified_name, command.short_doc))
|
||||
|
||||
def add_aliases_formatting(self, aliases):
|
||||
@@ -1268,7 +1268,7 @@ class MinimalHelpCommand(HelpCommand):
|
||||
if note:
|
||||
self.paginator.add_line(note, empty=True)
|
||||
|
||||
no_category = f'\u200b{self.no_category}'
|
||||
no_category = f"\u200b{self.no_category}"
|
||||
|
||||
def get_category(command, *, no_category=no_category):
|
||||
cog = command.cog
|
||||
@@ -1302,7 +1302,7 @@ class MinimalHelpCommand(HelpCommand):
|
||||
|
||||
filtered = await self.filter_commands(cog.get_commands(), sort=self.sort_commands)
|
||||
if filtered:
|
||||
self.paginator.add_line(f'**{cog.qualified_name} {self.commands_heading}**')
|
||||
self.paginator.add_line(f"**{cog.qualified_name} {self.commands_heading}**")
|
||||
for command in filtered:
|
||||
self.add_subcommand_formatting(command)
|
||||
|
||||
@@ -1322,7 +1322,7 @@ class MinimalHelpCommand(HelpCommand):
|
||||
if note:
|
||||
self.paginator.add_line(note, empty=True)
|
||||
|
||||
self.paginator.add_line(f'**{self.commands_heading}**')
|
||||
self.paginator.add_line(f"**{self.commands_heading}**")
|
||||
for command in filtered:
|
||||
self.add_subcommand_formatting(command)
|
||||
|
||||
|
Reference in New Issue
Block a user