diff options
| -rw-r--r-- | bot/formatter.py | 27 | 
1 files changed, 24 insertions, 3 deletions
diff --git a/bot/formatter.py b/bot/formatter.py index 503ae331d..cb7c99b88 100644 --- a/bot/formatter.py +++ b/bot/formatter.py @@ -61,16 +61,37 @@ class Formatter(HelpFormatter):              # get the args using the handy inspect module              argspec = getfullargspec(self.command.callback)              arguments = formatargspec(*argspec) -            args_no_type_hints = ", ".join(argspec[0]) +            for arg, annotation in argspec.annotations.items(): +                # remove module name to only show class name +                # discord.ext.commands.context.Context -> Context +                arguments = arguments.replace(f"{annotation.__module__}.", "") + +            # manipulate the argspec to make it valid python when 'calling' the do_<command> +            args_no_type_hints = argspec.args +            for kwarg in argspec.kwonlyargs: +                args_no_type_hints.append("{0}={0}".format(kwarg)) +            args_no_type_hints = "({0})".format(", ".join(args_no_type_hints))              # remove self from the args              arguments = arguments.replace("self, ", "")              args_no_type_hints = args_no_type_hints.replace("self, ", "") +            # indent every line in the help message +            helptext = "\n    ".join(self.command.help.split("\n")) +              # prepare the different sections of the help output, and add them to the paginator              definition = f"async def {stripped_command}{arguments}:" -            docstring = f"    \"\"\"\n    {self.command.help}\n    \"\"\"" -            invocation = f"    await do_{stripped_command}({args_no_type_hints})" +            doc_elems = [ +                '"""', +                helptext, +                '"""' +            ] + +            docstring = "" +            for elem in doc_elems: +                docstring += f'    {elem}\n' + +            invocation = f"    await do_{stripped_command}{args_no_type_hints}"              self._paginator.add_line(definition)              self._paginator.add_line(docstring)              self._paginator.add_line(invocation)  |