Refactor fuzzy help and clean up help command #2122

Merged
Tobotimus merged 3 commits from V3/bugfix/2031 into V3/develop 2018-09-24 02:34:40 +02:00
Tobotimus commented 2018-09-11 14:16:55 +02:00 (Migrated from github.com)

I'm really sorry this is a big diff. There was lots to refactor though.

What's changed:

  • Fixed issues mentioned on #2031
  • Fuzzy help displays more like help manual
  • Fuzzy help is easier and more flexible to use
  • Fuzzy help string-matching ratio lowered to 80
  • Help formatter is more extendable
  • Help command has been optimized, cleaned up and better incorporates fuzzy help
  • Added async_filter and async_enumerate utility functions because I was using them for this PR, then no longer needed them, but decided they might be useful anyway.
  • Moved clean_prefix from the help formatter to commands.Context
  • Added Command.can_see(ctx: Context) -> bool method, which tries to mimic help formatter behaviour over whether a command can be seen in the current context.
I'm really sorry this is a big diff. There was lots to refactor though. What's changed: - Fixed issues mentioned on #2031 - Fuzzy help displays more like help manual - Fuzzy help is easier and more flexible to use - Fuzzy help string-matching ratio lowered to 80 - Help formatter is more extendable - Help command has been optimized, cleaned up and better incorporates fuzzy help - Added async_filter and async_enumerate utility functions because I was using them for this PR, then no longer needed them, but decided they might be useful anyway. - Moved `clean_prefix` from the help formatter to `commands.Context` - Added `Command.can_see(ctx: Context) -> bool` method, which tries to mimic help formatter behaviour over whether a command can be seen in the current context.
tekulvw (Migrated from github.com) reviewed 2018-09-11 14:16:55 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-09-11 14:16:55 +02:00
mikeshardmind (Migrated from github.com) requested changes 2018-09-23 12:50:51 +02:00
mikeshardmind (Migrated from github.com) left a comment

Okay, first of all, this works wonderfully, and I love the improvements this makes from a UX perspective.

There are a couple mostly small things I've noted below, and while I would not call any of them "must change", I'd prefer discussing them if you think there's a reason not to.

Okay, first of all, this works wonderfully, and I love the improvements this makes from a UX perspective. There are a couple mostly small things I've noted below, and while I would not call any of them "must change", I'd prefer discussing them if you think there's a reason not to.
@ -106,6 +106,36 @@ class Command(commands.Command):
# We should expose anything which might be a bug in the converter
raise exc
mikeshardmind (Migrated from github.com) commented 2018-09-23 12:29:02 +02:00

Is this really worth importing itertools for? This could easily just be

for cmd in (self, *self.parents):

Is this really worth importing itertools for? This could easily just be `for cmd in (self, *self.parents):`
@ -109,0 +135,4 @@
return False
return True
mikeshardmind (Migrated from github.com) commented 2018-09-23 12:30:46 +02:00

This logic only holds up with the default help formatter behavior, which can be changed while the bot is running by cogs. Do we care about this, or should we query the behavior of how the help formatter handles check failures?

This logic only holds up with the default help formatter behavior, which can be changed while the bot is running by cogs. Do we care about this, or should we query the behavior of how the help formatter handles check failures?
@ -237,3 +237,20 @@ class Context(commands.Context):
)
mikeshardmind (Migrated from github.com) commented 2018-09-23 12:34:32 +02:00

I think it might be worth adding me to context as

@property
def me(self):
    return self.guild.me if self.guid else self.bot.me

And use that here inside clean_prefix. There are many cases where the user/member object may be desired, and such a shortcut is nice to have.

I think it might be worth adding `me` to `context` as ```py @property def me(self): return self.guild.me if self.guid else self.bot.me ``` And use that here inside clean_prefix. There are many cases where the user/member object may be desired, and such a shortcut is nice to have.
@ -20,25 +20,24 @@ message to help page.
e.g. format_help_for(ctx, ctx.command, "Missing required arguments")
mikeshardmind (Migrated from github.com) commented 2018-09-23 12:44:35 +02:00

These credits at the top don't seem accurate anymore. The majority of the logic below is not equivalent to the work Danny or SirThane did. I'd like to see this modified to more appropriately credit their work as the work this is now building off of, rather than all of this being their work.

These credits at the top don't seem accurate anymore. The majority of the logic below is not equivalent to the work Danny or SirThane did. I'd like to see this modified to more appropriately credit their work as the work this is now building off of, rather than all of this being their work.
Tobotimus (Migrated from github.com) reviewed 2018-09-23 15:30:41 +02:00
@ -106,6 +106,36 @@ class Command(commands.Command):
# We should expose anything which might be a bug in the converter
raise exc
Tobotimus (Migrated from github.com) commented 2018-09-23 15:30:41 +02:00

Good point, it's not like parents is going to be a particular memory-hungry sequence.

Good point, it's not like `parents` is going to be a particular memory-hungry sequence.
Tobotimus (Migrated from github.com) reviewed 2018-09-23 15:32:45 +02:00
@ -109,0 +135,4 @@
return False
return True
Tobotimus (Migrated from github.com) commented 2018-09-23 15:32:44 +02:00

I'm happy with can_see being a simple combination of check verification and hidden, however I am happy to make that more clear in the docstring. This method could yet see a little tweak in the upcoming permissions overhaul too.

I'm happy with `can_see` being a simple combination of check verification and `hidden`, however I am happy to make that more clear in the docstring. This method could yet see a little tweak in the upcoming permissions overhaul too.
mikeshardmind (Migrated from github.com) reviewed 2018-09-23 15:52:37 +02:00
@ -109,0 +135,4 @@
return False
return True
mikeshardmind (Migrated from github.com) commented 2018-09-23 15:52:37 +02:00

I guess that's fair enough. Anything calling it should be aware that if the formatter has been told to display all visible commands, this loses meaning, and a doc string change is enough to signal that.

I guess that's fair enough. Anything calling it should be aware that if the formatter has been told to display all visible commands, this loses meaning, and a doc string change is enough to signal that.
mikeshardmind (Migrated from github.com) approved these changes 2018-09-23 16:11:57 +02:00
mikeshardmind (Migrated from github.com) left a comment

👍 This one's ready to go.

:+1: This one's ready to go.
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2122
No description provided.