Remove !join

bug. Now it should actually work even if the user has no warnings.
Also don't list expired/deleted warnings as unacknowledged.
Warning expiration can now be modified via !fwarn set, and the default
expiration is now 30d instead of never (never can be manually specified
along with a handful of aliases that mean the same thing).
This commit is contained in:
skizzerz 2016-06-14 12:02:54 -05:00
parent 2f62c4a867
commit b39828be7f
4 changed files with 65 additions and 13 deletions

View File

@ -811,7 +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.",
"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_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}.",
@ -859,6 +859,7 @@
"access_account": "Account {0} has access +{1}.",
"no_access_host": "Host {0} does not have any access.",
"access_host": "Host {0} has access +{1}.",
"never_aliases": ["never", "infinite", "infinity", "permanent", "p"],
"_": " vim: set sw=4 expandtab:"
}

View File

@ -396,7 +396,7 @@ def has_unacknowledged_warnings(acc, hostmask):
if peid is None:
return False
c = conn.cursor()
c.execute("""SELECT MIN(acknowledged)
c.execute("""SELECT COALESCE(MIN(acknowledged), 1)
FROM warning
WHERE
target = ?
@ -419,7 +419,12 @@ def list_all_warnings(list_all=False, skip=0, show=0):
warning.expires,
CASE WHEN warning.expires IS NULL OR warning.expires > datetime('now')
THEN 0 ELSE 1 END AS expired,
warning.acknowledged,
CASE WHEN warning.deleted
OR (
warning.expires IS NOT NULL
AND warning.expires <= datetime('now')
)
THEN 1 ELSE warning.acknowledged END AS acknowledged,
warning.deleted,
warning.reason
FROM warning
@ -471,7 +476,12 @@ def list_warnings(acc, hostmask, expired=False, deleted=False, skip=0, show=0):
warning.expires,
CASE WHEN warning.expires IS NULL OR warning.expires > datetime('now')
THEN 0 ELSE 1 END AS expired,
warning.acknowledged,
CASE WHEN warning.deleted
OR (
warning.expires IS NOT NULL
AND warning.expires <= datetime('now')
)
THEN 1 ELSE warning.acknowledged END AS acknowledged,
warning.deleted,
warning.reason
FROM warning
@ -643,12 +653,12 @@ def del_warning(warning, acc, hm):
id = ?
AND deleted = 0""", (peid, warning))
def set_warning(warning, reason, notes):
def set_warning(warning, expires, reason, notes):
with conn:
c = conn.cursor()
c.execute("""UPDATE warning
SET reason = ?, notes = ?
WHERE id = ?""", (reason, notes, warning))
SET reason = ?, notes = ?, expires = ?
WHERE id = ?""", (reason, notes, expires, warning))
def acknowledge_warning(warning):
with conn:

View File

@ -60,6 +60,7 @@ QUIET_PREFIX = "" # "" or "~q:"
# The bot will automatically toggle those modes of people joining
AUTO_TOGGLE_MODES = ""
DEFAULT_EXPIRY = "30d"
LEAVE_PENALTY = 1
LEAVE_EXPIRY = "30d"
IDLE_PENALTY = 1

View File

@ -8443,7 +8443,7 @@ def fwarn(cli, nick, chan, rest):
try:
warn_id = int(params.pop(0))
except (IndexError, ValueError):
reply(cli, nick, chan, messages["fwarn_del_syntax"])
reply(cli, nick, chan, messages["fwarn_set_syntax"])
return
warning = db.get_warning(warn_id)
@ -8455,11 +8455,46 @@ def fwarn(cli, nick, chan, rest):
if len(rsp) == 1:
rsp.append(None)
reason, notes = rsp
reason = reason.strip()
# check for modified expiry
expires = warning["expires"]
rsp = reason.split(" ", 1)
if rsp[0] and rsp[0][0] == "~":
if len(rsp) == 1:
rsp.append("")
expires, reason = rsp
expires = expires[1:]
reason = reason.strip()
if expires in messages["never_aliases"]:
expires = None
else:
suffix = expires[-1]
try:
amount = int(expires[:-1])
except ValueError:
reply(cli, nick, chan, messages["fwarn_expiry_invalid"])
return
if amount <= 0:
reply(cli, nick, chan, messages["fwarn_expiry_invalid"])
return
issued = datetime.strptime(warning["issued"], "%Y-%m-%d %H:%M:%S")
if suffix == "d":
expires = issued + timedelta(days=amount)
elif suffix == "h":
expires = issued + timedelta(hours=amount)
elif suffix == "m":
expires = issued + timedelta(minutes=amount)
else:
reply(cli, nick, chan, messages["fwarn_expiry_invalid_suffix"])
return
# maintain existing reason if none was specified
if not reason:
reply(cli, nick, chan, messages["fwarn_reason_required"])
return
reason = warning["reason"]
# maintain existing notes if none were specified
if notes is not None:
@ -8469,7 +8504,7 @@ def fwarn(cli, nick, chan, rest):
else:
notes = warning["notes"]
db.set_warning(warn_id, reason, notes)
db.set_warning(warn_id, expires, reason, notes)
reply(cli, nick, chan, messages["fwarn_done"])
return
@ -8553,7 +8588,12 @@ def fwarn(cli, nick, chan, rest):
notes = notes.strip()
# convert expires into a proper datetime
if expires is not None:
if expires is None:
expires = var.DEFAULT_EXPIRY
if expires.lower() in messages["never_aliases"]:
expires = None
else:
suffix = expires[-1]
try:
amount = int(expires[:-1])