-
-
Notifications
You must be signed in to change notification settings - Fork 41
fix: enable the banning nonserver users #981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThe 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 membersequenceDiagram
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
Class diagram for updated ban command parameterclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this 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
userparameter to something more descriptive (e.g.targetoruser_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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| dm_action="banned", | ||
| actions=[ | ||
| (ctx.guild.ban(member, reason=flags.reason, delete_message_seconds=flags.purge * 86400), type(None)), |
There was a problem hiding this comment.
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.
| 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)), | |
| ], |
8d3959f to
ba2e8c4
Compare
Codecov Report❌ Patch coverage is
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
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
0836457 to
939acb2
Compare
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: