Editing a mute's duration sometimes applies the wrong timeout duration to the target #101

Open
opened 2025-04-25 14:30:06 -04:00 by cswimr · 0 comments
Owner

Please confirm that;

  • I have checked that this bug does not already have an opened/closed issue or pull request associated with it.
  • I have checked that I am on the latest version of Red-DiscordBot, and SeaCogs.

Hosting

Docker

What happened?

When editing a mute's duration, the wrong timeout duration will sometimes be applied to the target user. The expected behavior is that the timeout duration is the sum of the mute's original timestamp and the resulting duration converted to seconds. I suspect that the timestamp of the edit is being used instead of the original moderation timestamp.

Offending code

@classmethod
async def duration_edit_handler(cls, interaction: Interaction, old_moderation: Moderation, new_moderation: Moderation) -> bool: # pylint: disable=unused-argument
if (time() - new_moderation.unix_timestamp) + new_moderation.duration.total_seconds() > 2419200:
await interaction.response.send_message(content=error("Please provide a duration that is less than 28 days from the initial moderation."), ephemeral=True)
return False
try:
member = await interaction.guild.fetch_member(new_moderation.target_id)
await member.timeout(
new_moderation.duration,
reason=f"Case #{new_moderation.id:,} edited by {interaction.user.id}",
)
except NotFound:
pass
return True

Reproduction steps

  1. Moderate someone with the mute case type.
  2. Edit the resulting moderation.
  3. Observe on the target's client that the time listed until they are timed out is not what it should be.

Relevant traceback or logs

{
  "moderation_id": 13668,
  "timestamp": 1745093118,
  "moderation_type": "mute",
  "target_type": "user",
  "target_id": REMOVED,
  "moderator_id": REMOVED,
  "role_id": null,
  "duration": "72:00:00",
  "end_timestamp": 1745352318,
  "reason": "REMOVED",
  "resolved": false,
  "resolved_by": null,
  "resolve_reason": null,
  "expired": true,
  "changes": [
    {
      "bot": null,
      "type": "ORIGINAL",
      "timestamp": 1745093118,
      "user_id": REMOVED,
      "reason": "REMOVED",
      "duration": "168:00:00",
      "end_timestamp": 1745697918
    },
    {
      "bot": null,
      "type": "EDIT",
      "timestamp": 1745261547,
      "user_id": REMOVED,
      "reason": null,
      "duration": "72:00:00",
      "end_timestamp": 1745352318
    }
  ],
  "metadata": {}
}
### Please confirm that; - [x] I have checked that this bug does not already have an opened/closed [issue](https://www.coastalcommits.com/cswimr/SeaCogs/issues) or [pull request](https://www.coastalcommits.com/cswimr/SeaCogs/pulls) associated with it. - [x] I have checked that I am on the latest version of [Red-DiscordBot](https://github.com/CogCreators/Red-DiscordBot), and SeaCogs. ### Hosting Docker ### What happened? When editing a mute's duration, the wrong timeout duration will sometimes be applied to the target user. The expected behavior is that the timeout duration is the sum of the mute's original timestamp and the resulting duration converted to seconds. I suspect that the timestamp of the edit is being used instead of the original moderation timestamp. #### Offending code https://c.csw.im/cswimr/SeaCogs/src/commit/ece4cc74f6bf5ab14b368c7c40d084ba23eb887d/aurora/models/moderation_types.py#L550-L565 ### Reproduction steps 1. Moderate someone with the `mute` case type. 2. Edit the resulting moderation. 3. Observe on the target's client that the time listed until they are timed out is not what it should be. ### Relevant traceback or logs ```json { "moderation_id": 13668, "timestamp": 1745093118, "moderation_type": "mute", "target_type": "user", "target_id": REMOVED, "moderator_id": REMOVED, "role_id": null, "duration": "72:00:00", "end_timestamp": 1745352318, "reason": "REMOVED", "resolved": false, "resolved_by": null, "resolve_reason": null, "expired": true, "changes": [ { "bot": null, "type": "ORIGINAL", "timestamp": 1745093118, "user_id": REMOVED, "reason": "REMOVED", "duration": "168:00:00", "end_timestamp": 1745697918 }, { "bot": null, "type": "EDIT", "timestamp": 1745261547, "user_id": REMOVED, "reason": null, "duration": "72:00:00", "end_timestamp": 1745352318 } ], "metadata": {} } ```
cswimr self-assigned this 2025-04-25 14:30:06 -04:00
cswimr added this to the Aurora Release milestone 2025-04-27 00:27:55 -04:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cswimr/SeaCogs#101
No description provided.