Fix automod punishment duration always saving as 0 seconds - #279
Merged
Conversation
Co-authored-by: LightSage <46062298+LightSage@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
LightSage
August 27, 2026 03:14
View session
LightSage
marked this pull request as ready for review
August 27, 2026 03:14
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes automod mute and ban durations by converting every component of ShortTime's relativedelta into total seconds, preventing hour- and minute-based durations from being persisted as zero. Sequence diagram for automod punishment duration conversionsequenceDiagram
actor Moderator
participant UI as ConfigurePunishmentDurationButton
participant Rules as add_automod_rules
participant Storage as AutomodRuleStorage
Moderator->>UI: callback(interaction)
UI->>UI: ShortTime.delta
UI->>UI: selected_punishment_duration = days*86400 + hours*3600 + minutes*60 + seconds
UI->>Rules: punishment_duration
Rules->>Rules: punishment_duration.delta
Rules->>Rules: duration = days*86400 + hours*3600 + minutes*60 + seconds
Rules->>Storage: Store BAN or MUTE duration
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="lightning/cogs/automod/cog.py" line_range="299-301" />
<code_context>
if punishment.name in ("BAN", "MUTE") and punishment_duration:
- punishment_payload['duration'] = punishment_duration.delta.seconds
+ delta = punishment_duration.delta
+ punishment_payload['duration'] = delta.days * 86400 + delta.hours * 3600 + delta.minutes * 60 \
+ + delta.seconds
payload = {"guild_id": ctx.guild.id,
</code_context>
<issue_to_address>
**issue (bug_risk):** `add_automod_rules` still converts `ShortTime` values containing years or months to zero seconds because the calculation ignores `delta.years` and `delta.months`. Inputs such as `1mo` or `1y` are accepted by `ShortTime`, so a Mute duration becomes an indefinite mute and a Ban duration is treated as permanent.
**Triggers:** When the slash command is given a punishment duration containing months or years, such as `1mo` or `1y`.
**Suggested fix:** Reject calendar-based units for this command, or convert the requested duration using an explicitly defined calendar-duration policy before storing seconds.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and if the conversion is wrong, BAN or MUTE rules could be saved with incorrect durations and restrict users for too long or too little. Reverting would not change rules already saved, but those configurations can be corrected or removed.
Blocking findings: lightning/cogs/automod/cog.py:301
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Setting a Mute/Ban punishment duration via the automod interactive UI's "Configure Punishment Duration" modal always persisted a duration of
0, regardless of what was entered (e.g.30m,2h).Root cause
ShortTimeparses durations into adateutil.relativedelta, which keepsdays,hours,minutes, andsecondsas distinct components (no auto-normalization into a single unit). The duration-to-seconds conversion only summeddaysandseconds, silently discardinghoursandminutes.Changes
lightning/cogs/automod/ui.py—ConfigurePunishmentDurationButton.callbacknow includeshoursandminuteswhen computingselected_punishment_duration.lightning/cogs/automod/cog.py—add_automod_ruleshad the identical bug when convertingpunishment_durationto a stored duration; fixed with the same logic for consistency.Summary by Sourcery
Bug Fixes: