diff options
author | 2019-11-16 21:07:24 +1100 | |
---|---|---|
committer | 2019-11-16 21:07:24 +1100 | |
commit | af44f629dc5666ea17dd435dd3329784651c4412 (patch) | |
tree | 860c262df319ddf7058790135b60fb9e3e6b1065 | |
parent | Show a maximum of 8 commands per page rather than 5. (diff) |
Apply suggestions from review
- Description was the same as prefix parameter of paginator
- Cleanup is redundant pending closure of #514
- Clean/fix couple if statements in help.py
-rw-r--r-- | bot/cogs/help.py | 14 | ||||
-rw-r--r-- | bot/pagination.py | 23 |
2 files changed, 13 insertions, 24 deletions
diff --git a/bot/cogs/help.py b/bot/cogs/help.py index cd8c797b4..76d584d64 100644 --- a/bot/cogs/help.py +++ b/bot/cogs/help.py @@ -126,7 +126,8 @@ class CustomHelpCommand(HelpCommand): choices.add(str(c)) # all aliases if it's just a command - choices.update(n for n in c.aliases if isinstance(c, Command)) + if isinstance(c, Command): + choices.update(c.aliases) # else aliases with parent if group. we need to strip() in case it's a Command and `full_parent` is None, # otherwise we get 2 commands: ` help` and normal `help`. @@ -137,7 +138,7 @@ class CustomHelpCommand(HelpCommand): choices.update(self.context.bot.cogs) # all category names - choices.update(getattr(n, "category", None) for n in self.context.bot.cogs if hasattr(n, "category")) + choices.update(n.category for n in self.context.bot.cogs if hasattr(n, "category")) return choices def command_not_found(self, string: str) -> "HelpQueryNotFound": @@ -164,7 +165,7 @@ class CustomHelpCommand(HelpCommand): embed = Embed(colour=Colour.red(), title=str(error)) if getattr(error, "possible_matches", None): - matches = "\n".join(f"`{n}`" for n in error.possible_matches.keys()) + matches = "\n".join(f"`{n}`" for n in error.possible_matches) embed.description = f"**Did you mean:**\n{matches}" await self.context.send(embed=embed) @@ -285,14 +286,13 @@ class CustomHelpCommand(HelpCommand): f"\n*{c.short_doc or 'No details provided.'}*" for c in filtered_commands ] - description = f"**{category.name}**\n*{category.description}*" + description = f"```**{category.name}**\n*{category.description}*" if lines: description += "\n\n**Commands:**" await LinePaginator.paginate( - lines, self.context, embed, max_lines=COMMANDS_PER_PAGE, - max_size=2040, description=description, cleanup=True + lines, self.context, embed, prefix=description, max_lines=COMMANDS_PER_PAGE, max_size=2040 ) async def send_bot_help(self, mapping: dict) -> None: @@ -350,7 +350,7 @@ class CustomHelpCommand(HelpCommand): # add any remaining command help that didn't get added in the last iteration above. pages.append(formatted) - await LinePaginator.paginate(pages, self.context, embed=embed, max_lines=1, max_size=2040, cleanup=True) + await LinePaginator.paginate(pages, self.context, embed=embed, max_lines=1, max_size=2040) class Help(Cog): diff --git a/bot/pagination.py b/bot/pagination.py index f2cf192c4..bb49ead5e 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -1,9 +1,8 @@ import asyncio import logging -from contextlib import suppress from typing import Iterable, List, Optional, Tuple -from discord import Embed, HTTPException, Member, Message, Reaction +from discord import Embed, Member, Message, Reaction from discord.abc import User from discord.ext.commands import Context, Paginator @@ -101,8 +100,6 @@ class LinePaginator(Paginator): footer_text: str = None, url: str = None, exception_on_empty_embed: bool = False, - description: str = '', - cleanup: bool = False ) -> Optional[Message]: """ Use a paginator and set of reactions to provide pagination over a set of lines. @@ -114,9 +111,6 @@ class LinePaginator(Paginator): Pagination will also be removed automatically if no reaction is added for five minutes (300 seconds). - The description is a string that should appear at the top of every page. - If cleanup is True, the paginated message will be deleted when :x: reaction is added. - Example: >>> embed = Embed() >>> embed.set_author(name="Some Operation", url=url, icon_url=icon) @@ -167,7 +161,7 @@ class LinePaginator(Paginator): log.debug(f"Paginator created with {len(paginator.pages)} pages") - embed.description = description + paginator.pages[current_page] + embed.description = paginator.pages[current_page] if len(paginator.pages) <= 1: if footer_text: @@ -211,11 +205,6 @@ class LinePaginator(Paginator): if reaction.emoji == DELETE_EMOJI: log.debug("Got delete reaction") - if cleanup: - with suppress(HTTPException, AttributeError): - log.debug("Deleting help message") - await message.delete() - return break if reaction.emoji == FIRST_EMOJI: @@ -226,7 +215,7 @@ class LinePaginator(Paginator): embed.description = "" await message.edit(embed=embed) - embed.description = description + paginator.pages[current_page] + embed.description = paginator.pages[current_page] if footer_text: embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})") else: @@ -241,7 +230,7 @@ class LinePaginator(Paginator): embed.description = "" await message.edit(embed=embed) - embed.description = description + paginator.pages[current_page] + embed.description = paginator.pages[current_page] if footer_text: embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})") else: @@ -260,7 +249,7 @@ class LinePaginator(Paginator): embed.description = "" await message.edit(embed=embed) - embed.description = description + paginator.pages[current_page] + embed.description = paginator.pages[current_page] if footer_text: embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})") @@ -281,7 +270,7 @@ class LinePaginator(Paginator): embed.description = "" await message.edit(embed=embed) - embed.description = description + paginator.pages[current_page] + embed.description = paginator.pages[current_page] if footer_text: embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})") |