ClemBot
ClemBot copied to clipboard
Server-wide and Channel-wide Command Disabling
Command Restrictions
This PR adds a new cog and a way to disable commands in specific channels or server-wide. Resolves #765.
Features
- Command Cog
- Name:
command(aliases:cmd)- Checks the status of a command for a guild and channel.
- Arguments:
<command name> - Examples:
!command help,!command slots
- Sub-commands:
- Name:
enable(aliases:on)- Enables this command in a specific channel or server-wide.
- Arguments:
<command name> [channel] - Required Claims:
manage_commands - Examples:
!command enable search #general-chat,!command enable slots
- Name:
disable(aliases:off)- Disables this command in a specific channel or server-wide.
- Arguments:
<command name> [channel] [silently fail] - Required Claim:
manage_commands - If silently fail is
true, the user will not be notified that the command is disabled. - Examples:
!command disable trivia true,!command disable slots #clem-bot-discussion
- Name:
- Name:
- Two new claims:
manage_commands: Allows for enabling and disabling of commands.bypass_disabled_commands: Allows for a user or role to bypass ANY disabled commands.
- Cogs can optionally opt-out of allowing users to disable the command.
- Example:
@ext.command() @ext.allow_disable(False) # by default, this is set to True and is not necessary to allow disabling async def my_command(self, ctx: ext.ClemBotCtx) -> None: # ...
API Routes
- [GET]
bot/commands/{GuildId}/{ChannelId}/{CommandName}/status- Checks whether the given command is disabled in either the given guild or channel.
- Returns:
disabled: bool silently_fail: bool - [GET]
bot/commands/{GuildId}/{ChannelId}/{CommandName}/details- Gets the details for command restrictions for the given command name in the given guild and channel.
- Returns:
command_name: str disabled: bool guild_id: int channel_ids: list[int] - [PUT]
bot/commands/disable- Disables the given command.
- If the given command was previously disabled 1 or more channels and is now being disabled server-wide, the record for the channel disable will be removed.
- Body:
command_name: str guild_id: int channel_id: int | None silently_fail: bool = False- Returns:
id: int
- [DELETE]
bot/commands/enable- Enables the given command.
- If the given command was previously disabled 1 or more channels and is being enabled server-wide, the record for the channel disable will be removed.
- Body:
command_name: str guild_id: int channel_id: int | None- Returns:
id: int
Other
- Disallowed disabling for the
!helpand!commandcommands. - Fixed a small typo in the
tag_cog.pydocumentation (it was really bothering me). - Renamed
CommandMetricsServicetoCommandService.
To-Do
- [x] Create a migration to include the new claims and table.
- [x] Finish enabling and disabling in the API.
- [x] Finish enabling and disabling in the bot.
- [ ] Move claims checking to a service (as requested by @Jay-Madden).
- [x] Check for
bypass_disabled_commandsclaim pre-status. - [ ] Test
- [ ] Add documentation to Wiki.
- [ ] ~Beg @Jay-Madden to review the PR several times.~
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
Static type linting failed: Please see CI error output for details and fix the PRs typing
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
Static type linting failed: Please see CI error output for details and fix the PRs typing
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder
Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder
Static type linting failed: Please see CI error output for details and fix the PRs typing