ClemBot icon indicating copy to clipboard operation
ClemBot copied to clipboard

Server-wide and Channel-wide Command Disabling

Open jkriste opened this issue 3 years ago • 6 comments

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
  • 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 !help and !command commands.
  • Fixed a small typo in the tag_cog.py documentation (it was really bothering me).
  • Renamed CommandMetricsService to CommandService.

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_commands claim pre-status.
  • [ ] Test
  • [ ] Add documentation to Wiki.
  • [ ] ~Beg @Jay-Madden to review the PR several times.~

jkriste avatar Aug 21 '22 23:08 jkriste

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Aug 21 '22 23:08 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Aug 21 '22 23:08 github-actions[bot]

Static type linting failed: Please see CI error output for details and fix the PRs typing

github-actions[bot] avatar Aug 24 '22 05:08 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Aug 24 '22 05:08 github-actions[bot]

Static type linting failed: Please see CI error output for details and fix the PRs typing

github-actions[bot] avatar Aug 26 '22 04:08 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Aug 26 '22 04:08 github-actions[bot]

isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder

github-actions[bot] avatar Sep 17 '22 18:09 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Sep 21 '22 00:09 github-actions[bot]

isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder

github-actions[bot] avatar Sep 22 '22 18:09 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Sep 22 '22 18:09 github-actions[bot]

isort linting failed: Please run poetry run isort . from the ClemBot.Bot folder

github-actions[bot] avatar Sep 23 '22 03:09 github-actions[bot]

Black linting failed: Please run poetry run black bot from the ClemBot.Bot folder

github-actions[bot] avatar Sep 23 '22 03:09 github-actions[bot]

Static type linting failed: Please see CI error output for details and fix the PRs typing

github-actions[bot] avatar Sep 23 '22 03:09 github-actions[bot]