diff options
| author | 2021-04-01 21:20:04 +0100 | |
|---|---|---|
| committer | 2021-04-01 21:20:04 +0100 | |
| commit | adf2801e1d0f1e2d4608d65ae37c072629ad32dc (patch) | |
| tree | b6c2353a1c546d8f394655ba228819f001bd2723 | |
| parent | Use tz aware timestamps and refactor for readibility - Stream cog (diff) | |
Ensure duration is always tz-aware
| -rw-r--r-- | bot/exts/moderation/stream.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bot/exts/moderation/stream.py b/bot/exts/moderation/stream.py index 50ed01e78..a54e95fd9 100644 --- a/bot/exts/moderation/stream.py +++ b/bot/exts/moderation/stream.py @@ -1,5 +1,5 @@ import logging -from datetime import timedelta +from datetime import timedelta, timezone import arrow import discord @@ -85,9 +85,14 @@ class Stream(commands.Cog): Alternatively, an ISO 8601 timestamp can be provided for the duration. """ log.trace(f"Attempting to give temporary streaming permission to {member} ({member.id}).") - # If duration is none then calculate default duration + if duration is None: + # If duration is None then calculate default duration duration = arrow.utcnow() + timedelta(minutes=VideoPermission.default_permission_duration) + elif duration.tzinfo is None: + # Make duration tz-aware. + # ISODateTime could already include tzinfo, this check is so it isn't overwritten. + duration.replace(tzinfo=timezone.utc) # Check if the member already has streaming permission already_allowed = any(Roles.video == role.id for role in member.roles) |