[V3] Adding support for appending help from custom commands.Converter #800

Closed
opened 2017-06-09 07:51:27 +02:00 by DeltaSigma130 · 5 comments
DeltaSigma130 commented 2017-06-09 07:51:27 +02:00 (Migrated from github.com)

This may be too niche, but having argument processing help through commands.Converter has been helpful to me. Here's some code that I've been using.

def command_arg_help(**cmdkwargs):
    def internal_func(f):
        helps = []
        for param in inspect.signature(f).parameters.values():
            if issubclass(param.annotation, commands.Converter):
                arg_help = getattr(param.annotation, 'arg_help')
                if arg_help is not None:
                    helps.append(arg_help)
        if helps:
            if f.__doc__:
                helps.insert(0, f.__doc__)
            f.__doc__ = '\n'.join(helps)
        @wraps(f)
        async def wrapper(*args, **kwargs):
            return await f(*args, **kwargs)
        return commands.command(**cmdkwargs)(wrapper)
    return internal_func
This may be too niche, but having argument processing help through commands.Converter has been helpful to me. Here's some code that I've been using. ```python def command_arg_help(**cmdkwargs): def internal_func(f): helps = [] for param in inspect.signature(f).parameters.values(): if issubclass(param.annotation, commands.Converter): arg_help = getattr(param.annotation, 'arg_help') if arg_help is not None: helps.append(arg_help) if helps: if f.__doc__: helps.insert(0, f.__doc__) f.__doc__ = '\n'.join(helps) @wraps(f) async def wrapper(*args, **kwargs): return await f(*args, **kwargs) return commands.command(**cmdkwargs)(wrapper) return internal_func
DeltaSigma130 commented 2017-06-09 07:53:54 +02:00 (Migrated from github.com)

Then, inside the commands.Converter class:

class ChampConverter(commands.Converter):
    arg_help = '''More help '''
Then, inside the commands.Converter class: ```python class ChampConverter(commands.Converter): arg_help = '''More help '''
DeltaSigma130 commented 2017-06-09 07:53:58 +02:00 (Migrated from github.com)

And then the decorator:

    @command_arg_help(aliases=('bio',))
    async def champ_bio(self, *, champ : ChampConverterDebug):
And then the decorator: ```python @command_arg_help(aliases=('bio',)) async def champ_bio(self, *, champ : ChampConverterDebug):
tekulvw commented 2017-06-12 18:17:37 +02:00 (Migrated from github.com)

I like the idea but not this exact implementation. I think I'll come up with a slightly modified one for V3 in the next week or two.

I like the idea but not this exact implementation. I think I'll come up with a slightly modified one for V3 in the next week or two.
DeltaSigma130 commented 2017-06-21 22:50:15 +02:00 (Migrated from github.com)

No problem. That was just the first implementation idea that came to me that seemed to work for my use case but still be general enough. Many other ways to accomplish the same thing.

No problem. That was just the first implementation idea that came to me that seemed to work for my use case but still be general enough. Many other ways to accomplish the same thing.
tekulvw commented 2018-06-07 07:28:52 +02:00 (Migrated from github.com)

I think we're going to go with the ideas in #967, having the bot respond when an argument conversion has failed rather than appending converter information to the help. It'll likely be more useful to the end user that way.

I think we're going to go with the ideas in #967, having the bot respond when an argument conversion has failed rather than appending converter information to the help. It'll likely be more useful to the end user that way.
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#800
No description provided.