Expiration date fixes for fwarn
- Always use UTC (time issued was already UTC, but expiration was not) - Remove some duplicate code about parsing expiration date - Round dates to the nearest minute
This commit is contained in:
parent
f8ed5c7dbd
commit
7a0c9b87e1
@ -811,8 +811,7 @@
|
||||
"fwarn_add_syntax": "Usage: fwarn add <nick[!user@host]|=account> [@]<points> [~expiry] [sanctions] <:reason> [| notes]",
|
||||
"fwarn_page_invalid": "Invalid page, must be a number 1 or greater.",
|
||||
"fwarn_points_invalid": "Invalid points, must be a number above 0.",
|
||||
"fwarn_expiry_invalid": "Invalid expiration amount, must be a number above 0 or 'never' for a warning that never expires.",
|
||||
"fwarn_expiry_invalid_suffix": "Invalid expiration suffix, must use either d, h, or m.",
|
||||
"fwarn_expiry_invalid": "Invalid expiration, must be a number above 0 followed by either d, h, or m, or 'never' for a warning that never expires.",
|
||||
"fwarn_cannot_add": "Cannot add warning, double-check your parameters (the nick might be wrong or you are not joined to the channel).",
|
||||
"fwarn_added": "Added warning {0}.",
|
||||
"fwarn_done": "Done.",
|
||||
|
@ -7975,15 +7975,23 @@ def add_warning(target, amount, actor, reason, notes=None, expires=None, need_ac
|
||||
exp_amount = int(expires[:-1])
|
||||
|
||||
if exp_suffix == "d":
|
||||
expires = datetime.now() + timedelta(days=exp_amount)
|
||||
expires = datetime.utcnow() + timedelta(days=exp_amount)
|
||||
elif exp_suffix == "h":
|
||||
expires = datetime.now() + timedelta(hours=exp_amount)
|
||||
expires = datetime.utcnow() + timedelta(hours=exp_amount)
|
||||
elif exp_suffix == "m":
|
||||
expires = datetime.now() + timedelta(minutes=exp_amount)
|
||||
expires = datetime.utcnow() + timedelta(minutes=exp_amount)
|
||||
else:
|
||||
raise ValueError("Invalid expiration string")
|
||||
elif isinstance(expires, int):
|
||||
expires = datetime.now() + timedelta(days=expires)
|
||||
expires = datetime.utcnow() + timedelta(days=expires)
|
||||
|
||||
# Round expires to the nearest minute (30s rounds up)
|
||||
if isinstance(expires, datetime):
|
||||
round_add = 0
|
||||
if expires.second >= 30:
|
||||
round_add = 1
|
||||
expires -= timedelta(seconds=expires.second, microseconds=expires.microsecond)
|
||||
expires += timedelta(minutes=round_add)
|
||||
|
||||
# determine if we need to automatically add any sanctions
|
||||
prev = db.get_warning_points(tacc, thm)
|
||||
@ -8523,9 +8531,15 @@ def fwarn(cli, nick, chan, rest):
|
||||
elif suffix == "m":
|
||||
expires = issued + timedelta(minutes=amount)
|
||||
else:
|
||||
reply(cli, nick, chan, messages["fwarn_expiry_invalid_suffix"])
|
||||
reply(cli, nick, chan, messages["fwarn_expiry_invalid"])
|
||||
return
|
||||
|
||||
round_add = 0
|
||||
if expires.second >= 30:
|
||||
round_add = 1
|
||||
expires -= timedelta(seconds=expires.second, microseconds=expires.microsecond)
|
||||
expires += timedelta(minutes=round_add)
|
||||
|
||||
# maintain existing reason if none was specified
|
||||
if not reason:
|
||||
reason = warning["reason"]
|
||||
@ -8627,29 +8641,12 @@ def fwarn(cli, nick, chan, rest):
|
||||
|
||||
if expires.lower() in messages["never_aliases"]:
|
||||
expires = None
|
||||
else:
|
||||
suffix = expires[-1]
|
||||
|
||||
try:
|
||||
amount = int(expires[:-1])
|
||||
warn_id = add_warning(target, points, nick, reason, notes, expires, need_ack, sanctions)
|
||||
except ValueError:
|
||||
reply(cli, nick, chan, messages["fwarn_expiry_invalid"])
|
||||
return
|
||||
|
||||
if amount <= 0:
|
||||
reply(cli, nick, chan, messages["fwarn_expiry_invalid"])
|
||||
return
|
||||
|
||||
if suffix == "d":
|
||||
expires = datetime.now() + timedelta(days=amount)
|
||||
elif suffix == "h":
|
||||
expires = datetime.now() + timedelta(hours=amount)
|
||||
elif suffix == "m":
|
||||
expires = datetime.now() + timedelta(minutes=amount)
|
||||
else:
|
||||
reply(cli, nick, chan, messages["fwarn_expiry_invalid_suffix"])
|
||||
return
|
||||
|
||||
warn_id = add_warning(target, points, nick, reason, notes, expires, need_ack, sanctions)
|
||||
if warn_id is False:
|
||||
reply(cli, nick, chan, messages["fwarn_cannot_add"])
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user