Skip to content

Commit

Permalink
[Help] Fixes some issues with fuzzy help (#2674)
Browse files Browse the repository at this point in the history
* Fixes some issues with fuzzy help

 - also cleans up some name shadowing which wasn't causing issues
 (curently)

* ver

* style
  • Loading branch information
Michael H authored and tekulvw committed May 15, 2019
1 parent 2d22ee7 commit 3c78fb4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion redbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __repr__(self) -> str:
)


__version__ = "3.1.0"
__version__ = "3.1.1"
version_info = VersionInfo.from_str(__version__)

# Filter fuzzywuzzy slow sequence matcher warning
Expand Down
44 changes: 21 additions & 23 deletions redbot/core/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ async def make_and_send_embeds(self, ctx, embed_dict: dict):

async def format_cog_help(self, ctx: Context, obj: commands.Cog):

commands = await self.get_cog_help_mapping(ctx, obj)
if not (commands or self.CONFIRM_UNAVAILABLE_COMMAND_EXISTENCES):
coms = await self.get_cog_help_mapping(ctx, obj)
if not (coms or self.CONFIRM_UNAVAILABLE_COMMAND_EXISTENCES):
return

description = obj.help
Expand All @@ -285,9 +285,9 @@ async def format_cog_help(self, ctx: Context, obj: commands.Cog):
if description:
emb["embed"]["title"] = f"*{description[:2044]}*"

if commands:
if coms:
command_text = "\n".join(
f"**{name}** {command.short_doc}" for name, command in sorted(commands.items())
f"**{name}** {command.short_doc}" for name, command in sorted(coms.items())
)
for i, page in enumerate(pagify(command_text, page_length=1000, shorten_by=0)):
if i == 0:
Expand All @@ -300,11 +300,11 @@ async def format_cog_help(self, ctx: Context, obj: commands.Cog):
await self.make_and_send_embeds(ctx, emb)

else:
commands_text = None
commands_header = None
if commands:
subtext = None
subtext_header = None
if coms:
subtext_header = "Commands:"
max_width = max(discord.utils._string_width(name) for name in commands.keys())
max_width = max(discord.utils._string_width(name) for name in coms.keys())

def width_maker(cmds):
doc_max_width = 80 - max_width
Expand All @@ -316,20 +316,17 @@ def width_maker(cmds):
yield nm, doc, max_width - width_gap

subtext = "\n".join(
f" {name:<{width}} {doc}"
for name, doc, width in width_maker(commands.items())
f" {name:<{width}} {doc}" for name, doc, width in width_maker(coms.items())
)

to_page = "\n\n".join(
filter(None, (description, signature[1:-1], subtext_header, subtext))
)
to_page = "\n\n".join(filter(None, (description, subtext_header, subtext)))
pages = [box(p) for p in pagify(to_page)]
await self.send_pages(ctx, pages, embed=False)

async def format_bot_help(self, ctx: Context):

commands = await self.get_bot_help_mapping(ctx)
if not commands:
coms = await self.get_bot_help_mapping(ctx)
if not coms:
return

description = ctx.bot.description or ""
Expand All @@ -343,7 +340,7 @@ async def format_bot_help(self, ctx: Context):
if description:
emb["embed"]["title"] = f"*{description[:2044]}*"

for cog_name, data in commands:
for cog_name, data in coms:

if cog_name:
title = f"**__{cog_name}:__**"
Expand All @@ -362,11 +359,12 @@ async def format_bot_help(self, ctx: Context):
await self.make_and_send_embeds(ctx, emb)

else:
to_join = []
if description:
to_join = [f"{description}\n"]
to_join.append(f"{description}\n")

names = []
for k, v in commands:
for k, v in coms:
names.extend(list(v.name for v in v.values()))

max_width = max(
Expand All @@ -382,7 +380,7 @@ def width_maker(cmds):
doc = doc[: doc_max_width - 3] + "..."
yield nm, doc, max_width - width_gap

for cog_name, data in commands:
for cog_name, data in coms:

title = f"{cog_name}:" if cog_name else "No Category:"
to_join.append(title)
Expand Down Expand Up @@ -426,17 +424,17 @@ async def command_not_found(self, ctx, help_for):
if fuzzy_commands:
ret = await format_fuzzy_results(ctx, fuzzy_commands, embed=use_embeds)
if use_embeds:
ret.set_author()
ret.set_author(name=f"{ctx.me.display_name} Help Menu", icon_url=ctx.me.avatar_url)
tagline = (await ctx.bot.db.help.tagline()) or self.get_default_tagline(ctx)
ret.set_footer(text=tagline)
await ctx.send(embed=ret)
else:
await ctx.send(ret)
elif self.CONFIRM_UNAVAILABLE_COMMAND_EXISTENCES:
ret = T_("Command *{command_name}* not found.").format(command_name=command_name)
ret = T_("Command *{command_name}* not found.").format(command_name=help_for)
if use_embeds:
emb = discord.Embed(color=(await ctx.embed_color()), description=ret)
emb.set_author(name=f"{ctx.me.display_name} Help Menu", icon_url=ctx.me.avatar_url)
ret = discord.Embed(color=(await ctx.embed_color()), description=ret)
ret.set_author(name=f"{ctx.me.display_name} Help Menu", icon_url=ctx.me.avatar_url)
tagline = (await ctx.bot.db.help.tagline()) or self.get_default_tagline(ctx)
ret.set_footer(text=tagline)
await ctx.send(embed=ret)
Expand Down

0 comments on commit 3c78fb4

Please sign in to comment.