From 72ec2f8b7f5ab581efb00def8d0cc72e8fc9d758 Mon Sep 17 00:00:00 2001 From: univ Date: Tue, 13 Feb 2018 15:59:30 +0000 Subject: added help for specific commands --- bot/cogs/formatter.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bot/cogs/formatter.py b/bot/cogs/formatter.py index d5cf8ba60..5999e891b 100644 --- a/bot/cogs/formatter.py +++ b/bot/cogs/formatter.py @@ -30,6 +30,35 @@ class Formatter(HelpFormatter): async def format(self): self._paginator = Paginator(prefix="```py") + if isinstance(self.command, Command): + # help on a specific command to look like an async function + + # example: + # async def (ctx, ): + # """ + # + # """ + # await do_(ctx, ) + + # strip the command of bot. and () + stripped_command = self.command.name.replace(PREFIX, "").replace("()", "") + # getting args using the handy inspect module + argspec = getfullargspec(self.command.callback) + arguments = formatargspec(*argspec) + args_no_type_hints = ", ".join(argspec[0]) + # remove self from the arguments + arguments = arguments.replace("self, ", "") + args_no_type_hints = args_no_type_hints.replace("self, ", "") + # first line of help containing the command name and arguments + definition = f"async def {stripped_command}{arguments}:" + self._paginator.add_line(definition) + # next few lines containing the help text formatted as a docstring + self._paginator.add_line(f" \"\"\"\n {self.command.help}\n \"\"\"") + # last line 'invoking' the command + self._paginator.add_line(f" await do_{stripped_command}({args_no_type_hints})") + + return self._paginator.pages + max_width = self.max_name_size def category_check(tup): -- cgit v1.2.3