Skip to content

Conversation

@meatharvester
Copy link
Collaborator

@meatharvester meatharvester commented Jul 26, 2025

Description

Changed ban.py to allow non-server members to be banned previously

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

tested with an admin account and unprivileged alt both attempting to ban a current guild member and a non-guild member

Additional Information

it does give a warning for not being able to DM a user (obviously this is because they're not apart of the guild)
i also got a warning for "No guild config found for guild_id" but i am pretty sure this is due to my server

Summary by Sourcery

Bug Fixes:

  • Allow banning of non-server members by changing the ban command parameter to discord.User

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 26, 2025

Reviewer's Guide

The ban command has been refactored to accept discord.User instead of discord.Member, enabling the bot to ban users who are not members of the server by updating the signature, permission check, and ban execution accordingly.

Sequence diagram for banning a non-server member

sequenceDiagram
    actor Moderator
    participant Bot
    participant Guild
    participant User
    Moderator->>Bot: Invoke ban command with User (not a member)
    Bot->>Bot: check_conditions(ctx, user, ctx.author, "ban")
    alt Permission granted
        Bot->>Guild: ban(user, reason, delete_message_seconds)
        Bot->>User: Attempt DM (may fail)
    else Permission denied
        Bot-->>Moderator: Abort ban
    end
Loading

Class diagram for updated ban command parameter

classDiagram
    class BanCommand {
        +ban(ctx: commands.Context[Tux], user: discord.User, flags: BanFlags)
    }
    class discord.User
    class discord.Member
    BanCommand ..> discord.User : now accepts
    BanCommand ..x discord.Member : no longer accepts
Loading

File-Level Changes

Change Details Files
Accept discord.User instead of discord.Member in ban command
  • Changed ban method signature parameter from Member to User
  • Updated permission check to pass User object
  • Modified execute_mod_action and guild.ban call to use User
tux/cogs/moderation/ban.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

@github-actions
Copy link
Contributor

github-actions bot commented Jul 26, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @cherryl1k - I've reviewed your changes - here's some feedback:

  • Update the method docstring and internal comments to reflect that it now accepts a discord.User instead of a member.
  • Verify that check_conditions is fully compatible with discord.User inputs (not only discord.Member).
  • Consider renaming the user parameter to something more descriptive (e.g. target or user_to_ban) to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Update the method docstring and internal comments to reflect that it now accepts a discord.User instead of a member.
- Verify that check_conditions is fully compatible with discord.User inputs (not only discord.Member).
- Consider renaming the `user` parameter to something more descriptive (e.g. `target` or `user_to_ban`) to avoid confusion.

## Individual Comments

### Comment 1
<location> `tux/cogs/moderation/ban.py:63` </location>
<code_context>
             silent=flags.silent,
             dm_action="banned",
             actions=[
-                (ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
+                (ctx.guild.ban(user, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
             ],
         )
</code_context>

<issue_to_address>
Banning by discord.User may fail if the user is not in the guild and the API expects a user ID.

If the user isn't cached or present in the guild, pass user.id to ctx.guild.ban to prevent API errors.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
            actions=[
                (ctx.guild.ban(user, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
            ],
=======
            actions=[
                (ctx.guild.ban(user.id, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
            ],
>>>>>>> REPLACE

</suggested_fix>

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 on lines 60 to -63
dm_action="banned",
actions=[
(ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Banning by discord.User may fail if the user is not in the guild and the API expects a user ID.

If the user isn't cached or present in the guild, pass user.id to ctx.guild.ban to prevent API errors.

Suggested change
dm_action="banned",
actions=[
(ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
actions=[
(ctx.guild.ban(user.id, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)),
],

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 26, 2025

Deploying tux with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2381c84
Status:⚡️  Build in progress...

View logs

@meatharvester meatharvester changed the title fix: enable the banning nonserver memeber fix: enable the banning nonserver users Jul 26, 2025
@meatharvester meatharvester force-pushed the ban-fix branch 3 times, most recently from 8d3959f to ba2e8c4 Compare July 31, 2025 20:08
@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 9.44%. Comparing base (784e178) to head (2381c84).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tux/cogs/moderation/ban.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #981   +/-   ##
=====================================
  Coverage   9.44%   9.44%           
=====================================
  Files        123     123           
  Lines      10406   10406           
  Branches    1277    1277           
=====================================
  Hits         983     983           
  Misses      9330    9330           
  Partials      93      93           
Flag Coverage Δ *Carryforward flag
database 0.31% <ø> (+<0.01%) ⬆️ Carriedforward from 784e178
integration 5.85% <0.00%> (ø)
unit 6.30% <0.00%> (ø)

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Core Bot Infrastructure 16.43% <ø> (ø)
Database Layer 0.00% <ø> (ø)
Bot Commands & Features 0.00% <0.00%> (ø)
Event & Error Handling ∅ <ø> (∅)
Utilities & Helpers ∅ <ø> (∅)
User Interface Components 0.00% <ø> (ø)
CLI Interface ∅ <ø> (∅)
External Service Wrappers ∅ <ø> (∅)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@meatharvester meatharvester force-pushed the ban-fix branch 3 times, most recently from 0836457 to 939acb2 Compare July 31, 2025 20:53
@electron271 electron271 merged commit b6a904b into main Aug 3, 2025
35 of 36 checks passed
@electron271 electron271 deleted the ban-fix branch August 3, 2025 00:41
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.

3 participants