add 0-point warnings, these need to be acknowledged but give no automatic sanctions
This commit is contained in:
parent
017a98608c
commit
b180f99051
@ -795,7 +795,7 @@
|
||||
"warn_help_syntax": "Usage: warn help <subcommand>",
|
||||
"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_points_invalid": "Invalid points, must be a non-negative integer.",
|
||||
"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}.",
|
||||
|
@ -88,52 +88,7 @@ def parse_warning_target(target, lower=False):
|
||||
return (None, None)
|
||||
return (tacc, thm)
|
||||
|
||||
def add_warning(cli, target, amount, actor, reason, notes=None, expires=None, sanctions=None):
|
||||
# make 0-point warnings no-op successfully, otherwise we add warnings when things like PART_PENALTY is 0
|
||||
if amount == 0:
|
||||
return False
|
||||
|
||||
tacc, thm = parse_warning_target(target)
|
||||
if tacc is None and thm is None:
|
||||
return False
|
||||
|
||||
if actor not in var.USERS and actor != botconfig.NICK:
|
||||
return False
|
||||
sacc = None
|
||||
shm = None
|
||||
if actor in var.USERS:
|
||||
sacc = var.USERS[actor]["account"]
|
||||
shm = actor + "!" + var.USERS[actor]["ident"] + "@" + var.USERS[actor]["host"]
|
||||
|
||||
# Turn expires into a datetime if we were passed a string; note that no error checking is performed here
|
||||
if isinstance(expires, str):
|
||||
exp_suffix = expires[-1]
|
||||
exp_amount = int(expires[:-1])
|
||||
|
||||
if exp_suffix == "d":
|
||||
expires = datetime.utcnow() + timedelta(days=exp_amount)
|
||||
elif exp_suffix == "h":
|
||||
expires = datetime.utcnow() + timedelta(hours=exp_amount)
|
||||
elif exp_suffix == "m":
|
||||
expires = datetime.utcnow() + timedelta(minutes=exp_amount)
|
||||
else:
|
||||
raise ValueError("Invalid expiration string")
|
||||
elif isinstance(expires, int):
|
||||
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
|
||||
if sanctions is None:
|
||||
sanctions = {}
|
||||
prev = db.get_warning_points(tacc, thm)
|
||||
cur = prev + amount
|
||||
def _get_auto_sanctions(sanctions, prev, cur):
|
||||
for (mn, mx, sanc) in var.AUTO_SANCTION:
|
||||
if (prev < mn and cur >= mn) or (prev >= mn and prev <= mx and cur <= mx):
|
||||
if "stasis" in sanc:
|
||||
@ -184,6 +139,52 @@ def add_warning(cli, target, amount, actor, reason, notes=None, expires=None, sa
|
||||
sanctions["tempban"] = ths
|
||||
else:
|
||||
sanctions["tempban"] = exp
|
||||
|
||||
|
||||
def add_warning(cli, target, amount, actor, reason, notes=None, expires=None, sanctions=None):
|
||||
tacc, thm = parse_warning_target(target)
|
||||
if tacc is None and thm is None:
|
||||
return False
|
||||
|
||||
if actor not in var.USERS and actor != botconfig.NICK:
|
||||
return False
|
||||
sacc = None
|
||||
shm = None
|
||||
if actor in var.USERS:
|
||||
sacc = var.USERS[actor]["account"]
|
||||
shm = actor + "!" + var.USERS[actor]["ident"] + "@" + var.USERS[actor]["host"]
|
||||
|
||||
# Turn expires into a datetime if we were passed a string; note that no error checking is performed here
|
||||
if isinstance(expires, str):
|
||||
exp_suffix = expires[-1]
|
||||
exp_amount = int(expires[:-1])
|
||||
|
||||
if exp_suffix == "d":
|
||||
expires = datetime.utcnow() + timedelta(days=exp_amount)
|
||||
elif exp_suffix == "h":
|
||||
expires = datetime.utcnow() + timedelta(hours=exp_amount)
|
||||
elif exp_suffix == "m":
|
||||
expires = datetime.utcnow() + timedelta(minutes=exp_amount)
|
||||
else:
|
||||
raise ValueError("Invalid expiration string")
|
||||
elif isinstance(expires, int):
|
||||
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
|
||||
if sanctions is None:
|
||||
sanctions = {}
|
||||
prev = db.get_warning_points(tacc, thm)
|
||||
cur = prev + amount
|
||||
if amount > 0:
|
||||
_get_auto_sanctions(sanctions, prev, cur)
|
||||
|
||||
sid = db.add_warning(tacc, thm, sacc, shm, amount, reason, notes, expires)
|
||||
if "stasis" in sanctions:
|
||||
@ -791,7 +792,7 @@ def fwarn(cli, nick, chan, rest):
|
||||
except ValueError:
|
||||
reply(cli, nick, chan, messages["fwarn_points_invalid"])
|
||||
return
|
||||
if points < 1:
|
||||
if points < 0:
|
||||
reply(cli, nick, chan, messages["fwarn_points_invalid"])
|
||||
return
|
||||
elif notes is not None:
|
||||
|
@ -3151,7 +3151,8 @@ def reaper(cli, gameid):
|
||||
if nck in rlist:
|
||||
var.ORIGINAL_ROLES[r].remove(nck)
|
||||
var.ORIGINAL_ROLES[r].add("(dced)"+nck)
|
||||
add_warning(cli, nck, var.IDLE_PENALTY, botconfig.NICK, messages["idle_warning"], expires=var.IDLE_EXPIRY)
|
||||
if var.IDLE_PENALTY:
|
||||
add_warning(cli, nck, var.IDLE_PENALTY, botconfig.NICK, messages["idle_warning"], expires=var.IDLE_EXPIRY)
|
||||
del_player(cli, nck, end_game = False, death_triggers = False)
|
||||
chk_win(cli)
|
||||
pl = list_players()
|
||||
@ -3167,7 +3168,7 @@ def reaper(cli, gameid):
|
||||
cli.msg(chan, messages["quit_death"].format(dcedplayer, get_reveal_role(dcedplayer)))
|
||||
else:
|
||||
cli.msg(chan, messages["quit_death_no_reveal"].format(dcedplayer))
|
||||
if var.PHASE != "join":
|
||||
if var.PHASE != "join" and var.PART_PENALTY:
|
||||
add_warning(cli, dcedplayer, var.PART_PENALTY, botconfig.NICK, messages["quit_warning"], expires=var.PART_EXPIRY)
|
||||
if not del_player(cli, dcedplayer, devoice = False, death_triggers = False):
|
||||
return
|
||||
@ -3176,7 +3177,7 @@ def reaper(cli, gameid):
|
||||
cli.msg(chan, messages["part_death"].format(dcedplayer, get_reveal_role(dcedplayer)))
|
||||
else:
|
||||
cli.msg(chan, messages["part_death_no_reveal"].format(dcedplayer))
|
||||
if var.PHASE != "join":
|
||||
if var.PHASE != "join" and var.PART_PENALTY:
|
||||
add_warning(cli, dcedplayer, var.PART_PENALTY, botconfig.NICK, messages["part_warning"], expires=var.PART_EXPIRY)
|
||||
if not del_player(cli, dcedplayer, devoice = False, death_triggers = False):
|
||||
return
|
||||
@ -3185,7 +3186,7 @@ def reaper(cli, gameid):
|
||||
cli.msg(chan, messages["account_death"].format(dcedplayer, get_reveal_role(dcedplayer)))
|
||||
else:
|
||||
cli.msg(chan, messages["account_death_no_reveal"].format(dcedplayer))
|
||||
if var.PHASE != "join":
|
||||
if var.PHASE != "join" and var.ACC_PENALTY:
|
||||
add_warning(cli, dcedplayer, var.ACC_PENALTY, botconfig.NICK, messages["acc_warning"], expires=var.ACC_EXPIRY)
|
||||
if not del_player(cli, dcedplayer, devoice = False, death_triggers = False):
|
||||
return
|
||||
@ -3626,7 +3627,8 @@ def leave_game(cli, nick, chan, rest):
|
||||
if nick in rset:
|
||||
var.ORIGINAL_ROLES[r].remove(nick)
|
||||
var.ORIGINAL_ROLES[r].add("(dced)"+nick)
|
||||
add_warning(cli, nick, var.LEAVE_PENALTY, botconfig.NICK, messages["leave_warning"], expires=var.LEAVE_EXPIRY)
|
||||
if var.LEAVE_PENALTY:
|
||||
add_warning(cli, nick, var.LEAVE_PENALTY, botconfig.NICK, messages["leave_warning"], expires=var.LEAVE_EXPIRY)
|
||||
if nick in var.PLAYERS:
|
||||
var.DCED_PLAYERS[nick] = var.PLAYERS.pop(nick)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user