aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2021-02-13 16:42:27 +0200
committerGravatar mbaruh <[email protected]>2021-02-13 16:42:27 +0200
commit2e4a069ac185d1d978070327e76faba4eefbd255 (patch)
treed31274d89ce37b273e75e41062f26c6e700a2786
parentAdd option to schedule threshold reset (diff)
Fixed on_message
Diffstat (limited to '')
-rw-r--r--bot/exts/moderation/defcon.py9
-rw-r--r--bot/exts/moderation/slowmode.py4
-rw-r--r--bot/utils/time.py6
3 files changed, 11 insertions, 8 deletions
diff --git a/bot/exts/moderation/defcon.py b/bot/exts/moderation/defcon.py
index 8c21a7327..28a1a425f 100644
--- a/bot/exts/moderation/defcon.py
+++ b/bot/exts/moderation/defcon.py
@@ -18,7 +18,7 @@ from bot.converters import DurationDelta, Expiry
from bot.exts.moderation.modlog import ModLog
from bot.utils.messages import format_user
from bot.utils.scheduling import Scheduler
-from bot.utils.time import humanize_delta, parse_duration_string
+from bot.utils.time import humanize_delta, parse_duration_string, relativedelta_to_timedelta
log = logging.getLogger(__name__)
@@ -99,10 +99,10 @@ class Defcon(Cog):
@Cog.listener()
async def on_member_join(self, member: Member) -> None:
"""Check newly joining users to see if they meet the account age threshold."""
- if self.threshold > relativedelta(days=0):
+ if self.threshold != relativedelta(days=0):
now = datetime.utcnow()
- if now - member.created_at < self.threshold: # TODO
+ if now - member.created_at < relativedelta_to_timedelta(self.threshold):
log.info(f"Rejecting user {member}: Account is too new")
message_sent = False
@@ -231,8 +231,7 @@ class Defcon(Cog):
def _log_threshold_stat(self, threshold: relativedelta) -> None:
"""Adds the threshold to the bot stats in days."""
- utcnow = datetime.utcnow()
- threshold_days = (utcnow + threshold - utcnow).total_seconds() / SECONDS_IN_DAY
+ threshold_days = relativedelta_to_timedelta(threshold).total_seconds() / SECONDS_IN_DAY
self.bot.stats.gauge("defcon.threshold", threshold_days)
async def _send_defcon_log(self, action: Action, actor: User) -> None:
diff --git a/bot/exts/moderation/slowmode.py b/bot/exts/moderation/slowmode.py
index c449752e1..d8baff76a 100644
--- a/bot/exts/moderation/slowmode.py
+++ b/bot/exts/moderation/slowmode.py
@@ -1,5 +1,4 @@
import logging
-from datetime import datetime
from typing import Optional
from dateutil.relativedelta import relativedelta
@@ -54,8 +53,7 @@ class Slowmode(Cog):
# Convert `dateutil.relativedelta.relativedelta` to `datetime.timedelta`
# Must do this to get the delta in a particular unit of time
- utcnow = datetime.utcnow()
- slowmode_delay = (utcnow + delay - utcnow).total_seconds()
+ slowmode_delay = time.relativedelta_to_timedelta(delay).total_seconds()
humanized_delay = time.humanize_delta(delay)
diff --git a/bot/utils/time.py b/bot/utils/time.py
index 5b197c350..a7b441327 100644
--- a/bot/utils/time.py
+++ b/bot/utils/time.py
@@ -110,6 +110,12 @@ def parse_duration_string(duration: str) -> Optional[relativedelta]:
return delta
+def relativedelta_to_timedelta(delta: relativedelta) -> datetime.timedelta:
+ """Converts a relativedelta object to a timedelta object."""
+ utcnow = datetime.datetime.utcnow()
+ return utcnow + delta - utcnow
+
+
def time_since(past_datetime: datetime.datetime, precision: str = "seconds", max_units: int = 6) -> str:
"""
Takes a datetime and returns a human-readable string that describes how long ago that datetime was.