Skip to content

fix(hotswap): support AutoShardedBot and add profile test action - #54

Merged
shamikkarkhanis merged 2 commits into
mainfrom
feature/capr-27-port-hotswapreload-command
Jan 31, 2026
Merged

fix(hotswap): support AutoShardedBot and add profile test action#54
shamikkarkhanis merged 2 commits into
mainfrom
feature/capr-27-port-hotswapreload-command

Conversation

@shamikkarkhanis

@shamikkarkhanis shamikkarkhanis commented Jan 31, 2026

Copy link
Copy Markdown
Member

Summary by Sourcery

Extend hotswap tooling compatibility and add a test action to the profile command.

New Features:

  • Add a 'test' action to the profile slash command that responds with a test message.

Bug Fixes:

  • Allow the hotswap tool to work with both Bot and AutoShardedBot interaction clients instead of only commands.Bot.

Enhancements:

  • Correct the Profile cog setup docstring to accurately describe the cog being registered.

@sourcery-ai

sourcery-ai Bot commented Jan 31, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extends the profile slash command with a new test action and its response, corrects the Profile cog setup docstring, and updates the hotswap tool to support both Bot and AutoShardedBot instances when validating the interaction client.

Sequence diagram for hotswap callback with Bot and AutoShardedBot support

sequenceDiagram
    actor User
    participant Discord
    participant Bot
    participant HotswapSelect

    User->>Discord: Trigger interaction
    Discord->>Bot: Send interaction
    Bot->>HotswapSelect: callback(interaction)
    HotswapSelect->>HotswapSelect: read cog_name from values
    HotswapSelect->>HotswapSelect: bot = interaction.client
    alt client is Bot or AutoShardedBot
        HotswapSelect->>HotswapSelect: proceed with hotswap logic
    else client is not Bot or AutoShardedBot
        HotswapSelect->>HotswapSelect: log error and return
    end
Loading

Updated class diagram for Profile cog and hotswap callback types

classDiagram
    class Profile {
        - bot : commands_Bot
        + Profile(bot : commands_Bot)
        + profile(interaction : discord_Interaction, action : str) void
        + handle_edit_action(interaction : discord_Interaction, action : str) void
        + handle_show_action(interaction : discord_Interaction) void
        + handle_delete_action(interaction : discord_Interaction) void
        - _create_profile_embed(user : discord_User_or_Member, profile : UserProfile) discord_Embed
    }

    class HotswapSelect {
        + values : list_str
        + callback(interaction : discord_Interaction) void
    }

    class Bot {
    }

    class AutoShardedBot {
    }

    class commands_Bot {
    }

    class discord_Interaction {
        + client : object
        + response : InteractionResponse
    }

    class InteractionResponse {
        + send_message(content : str, ephemeral : bool) void
    }

    class UserProfile {
    }

    Profile --> commands_Bot : uses
    Profile --> discord_Interaction : uses
    Profile --> UserProfile : uses
    Profile --> InteractionResponse : uses

    HotswapSelect --> discord_Interaction : uses
    HotswapSelect --> Bot : accepts
    HotswapSelect --> AutoShardedBot : accepts

    discord_Interaction --> InteractionResponse : has
Loading

File-Level Changes

Change Details Files
Add a new "test" sub-action to the profile slash command for quickly validating the Profile cog behavior.
  • Extend the profile slash command choices to include a "test" option.
  • Dispatch the new "test" action in the profile handler, replying with an ephemeral test message indicating "Profile Cog: Test Version 2.0".
capy_discord/exts/profile/profile.py
Fix the Profile cog setup function docstring to accurately describe the cog being registered.
  • Update the setup coroutine docstring from referencing "Sync cog" to "Profile cog".
capy_discord/exts/profile/profile.py
Allow the hotswap tool to work with both Bot and AutoShardedBot interaction clients.
  • Relax the type check for the interaction client from commands.Bot-only to accept both Bot and AutoShardedBot.
  • Adjust the corresponding error log message to mention Bot or AutoShardedBot instead of commands.Bot.
capy_discord/exts/tools/hotswap.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new test profile action appears to be a debugging hook; consider gating it behind a config flag or removing it before release so it doesn’t surface to end users in production.
  • When the interaction client is not a Bot/AutoShardedBot, you only log and return; consider also sending a brief ephemeral response to the user so they’re not left with a silent failure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `test` profile action appears to be a debugging hook; consider gating it behind a config flag or removing it before release so it doesn’t surface to end users in production.
- When the interaction client is not a `Bot`/`AutoShardedBot`, you only log and return; consider also sending a brief ephemeral response to the user so they’re not left with a silent failure.

## Individual Comments

### Comment 1
<location> `capy_discord/exts/profile/profile.py:70-71` </location>
<code_context>
             await self.handle_show_action(interaction)
         elif action == "delete":
             await self.handle_delete_action(interaction)
+        elif action == "test":
+            await interaction.response.send_message("Profile Cog: **Test Version 2.0**", ephemeral=True)

     async def handle_edit_action(self, interaction: discord.Interaction, action: str) -> None:
</code_context>

<issue_to_address>
**🚨 suggestion (security):** Consider gating the `test` action behind a permission or env check so it doesn't leak to regular users.

Since this is an internal verification endpoint, exposing it as a normal `profile` action makes it discoverable in help/autocomplete and leaks internal version info. Consider restricting it (e.g., owner-only, specific role, env flag) or moving it to a dedicated dev/debug cog.

```suggestion
        elif action == "test":
            # Restrict the internal test action to the bot owner so it is not usable by regular users.
            is_owner = await self.bot.is_owner(interaction.user)
            if not is_owner:
                await interaction.response.send_message(
                    "This action is restricted to the bot owner.",
                    ephemeral=True,
                )
                return

            await interaction.response.send_message(
                "Profile Cog: **Test Version 2.0**",
                ephemeral=True,
            )
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread capy_discord/exts/profile/profile.py
@shamikkarkhanis
shamikkarkhanis merged commit ea815eb into main Jan 31, 2026
4 checks passed
@shamikkarkhanis
shamikkarkhanis deleted the feature/capr-27-port-hotswapreload-command branch January 31, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant