[WIP] [V3] Cog-specific command mapping #2144

Closed
Zephyrkul wants to merge 9 commits from V3/feature/cog-command-map into V3/develop
Zephyrkul commented 2018-09-22 04:01:27 +02:00 (Migrated from github.com)

DO NOT MERGE - WORK IN PROGRESS

and also because my code is terrible

This PR only has the framework for this to function so far. I am currently working on refactoring CustomCommands and Alias to take advantage of the framework currently in this PR.

I've decided to open it early so I could get feedback and discuss the changes as they're done, and to mark this change as being actively worked on. As the framework is already committed to my fork, and as it is a little hacky, I would appreciate feedback on it before I get too far into refactoring CCs and Alias.

Alternate implementation ideas are, as always, welcome.

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Allows cogs to create their own command mapping, like bot.all_commands, that can resolve command names into commands. These mappings are unique to each cog and cannot overwrite each other. If the bot fails to find a command by that name, it will look through all cog mappings instead before failing. This allows cogs to create specialized commands that can't be created through @commands.command.

The mapping is automatically removed from the bot when the cog is unloaded; no __unload necessary. A cog can get its mapping via bot.get_cog_map(self).

This change allows specialized and/or dynamic commands, like those from CustomCommands and Alias, to count as full commands as far as the bot is concerned, while still allowing for dynamic changes simply via modifying the cog's own mapping without fear of damaging command data from other cogs or the bot itself.

Once complete, this PR will address #1920 and #1921, since special commands can be found via bot.all_commands / bot.get_command, simplifying commands like [p]cleanup bot that look for command messages. Special commands will also dispatch command events as normal. (CCs already has this feature due to #2051, but this will extend the feature to other special cog commands.)

Known issues

  • The cog mappings are searched through in the order they are loaded, and stop searching when they hit a match. I don't believe this to be much of an issue, especially since the standard commands are always first in line, but I figured that it was worth noting.
  • This changes bot.all_commands and bot.get_command to search through all mappings when read. A core_map property is available to read from only the bot's standard commands, ignoring cog mappings. I plan to implement an others_map method to return a map that only looks through mappings not belonging to the cog. Writes and deletions to bot.all_commands still only affect standard commands, so this won't change that side of the bot's functionality.
# DO NOT MERGE - WORK IN PROGRESS <sub><sup>and also because my code is terrible</sup></sub> This PR only has the framework for this to function so far. I am currently working on refactoring CustomCommands and Alias to take advantage of the framework currently in this PR. I've decided to open it early so I could get feedback and discuss the changes as they're done, and to mark this change as being actively worked on. As the framework is already committed to my fork, and as it is a little hacky, I would appreciate feedback on it before I get too far into refactoring CCs and Alias. Alternate implementation ideas are, as always, welcome. ### Type - [X] Bugfix - [X] Enhancement - [ ] New feature ### Description of the changes Allows cogs to create their own command mapping, like `bot.all_commands`, that can resolve command names into commands. These mappings are unique to each cog and cannot overwrite each other. If the bot fails to find a command by that name, it will look through all cog mappings instead before failing. This allows cogs to create specialized commands that can't be created through `@commands.command`. The mapping is automatically removed from the bot when the cog is unloaded; no `__unload` necessary. A cog can get its mapping via `bot.get_cog_map(self)`. This change allows specialized and/or dynamic commands, like those from CustomCommands and Alias, to count as full commands as far as the bot is concerned, while still allowing for dynamic changes simply via modifying the cog's own mapping without fear of damaging command data from other cogs or the bot itself. Once complete, this PR will address #1920 and #1921, since special commands can be found via `bot.all_commands` / `bot.get_command`, simplifying commands like `[p]cleanup bot` that look for command messages. Special commands will also dispatch command events as normal. (CCs already has this feature due to #2051, but this will extend the feature to other special cog commands.) ### Known issues - The cog mappings are searched through in the order they are loaded, and stop searching when they hit a match. I don't believe this to be much of an issue, especially since the standard commands are always first in line, but I figured that it was worth noting. - This changes `bot.all_commands` and `bot.get_command` to search through all mappings when read. A `core_map` property is available to read from only the bot's standard commands, ignoring cog mappings. I plan to implement an `others_map` method to return a map that only looks through mappings not belonging to the cog. Writes and deletions to `bot.all_commands` still only affect standard commands, so this won't change that side of the bot's functionality.
palmtree5 (Migrated from github.com) reviewed 2018-09-22 04:01:27 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-09-22 04:01:27 +02:00
Zephyrkul commented 2018-09-25 15:50:23 +02:00 (Migrated from github.com)

Pushed some CC changes. Feel free to take a look while I work on alias next.

Pushed some CC changes. Feel free to take a look while I work on alias next.
Zephyrkul commented 2019-03-04 08:03:48 +01:00 (Migrated from github.com)

Closing this in favor of a planned rewrite later on down the line.

Closing this in favor of a planned rewrite later on down the line.

Pull request closed

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!2144
No description provided.