Improve handling of kill and away/back/in/out.

Uses variables instead of hardcoded roles for kill. Doesn't warn about
incorrect use of away and back if var.OPT_IN_PING is on, and about
incorrect use of in/out if it's off. References #76.
This commit is contained in:
Vgr E.Barry 2015-01-02 18:11:07 -05:00
parent 32fd7b2fa2
commit 0984f79bd9

View File

@ -583,6 +583,7 @@ def away(cli, nick, chan, rest):
"""Use this to activate your away status (so you aren't pinged).""" """Use this to activate your away status (so you aren't pinged)."""
nick, _, _, cloak = parse_nick(nick) nick, _, _, cloak = parse_nick(nick)
if var.OPT_IN_PING: if var.OPT_IN_PING:
if not rest: # don't want to trigger on unrelated messages
cli.notice(nick, "Please use {0}in and {0}out to opt in or out of the ping list.".format(botconfig.CMD_CHAR)) cli.notice(nick, "Please use {0}in and {0}out to opt in or out of the ping list.".format(botconfig.CMD_CHAR))
return return
if nick in var.USERS: if nick in var.USERS:
@ -623,6 +624,7 @@ def back_from_away(cli, nick, chan, rest):
"""Unsets your away status.""" """Unsets your away status."""
nick, _, _, cloak = parse_nick(nick) nick, _, _, cloak = parse_nick(nick)
if var.OPT_IN_PING: if var.OPT_IN_PING:
if not rest:
cli.notice(nick, "Please use {0}in and {0}out to opt in or out of the ping list.".format(botconfig.CMD_CHAR)) cli.notice(nick, "Please use {0}in and {0}out to opt in or out of the ping list.".format(botconfig.CMD_CHAR))
return return
if nick in var.USERS: if nick in var.USERS:
@ -659,6 +661,7 @@ def get_in(cli, nick, chan, rest):
"""Puts yourself in the ping list.""" """Puts yourself in the ping list."""
nick, _, _, cloak = parse_nick(nick) nick, _, _, cloak = parse_nick(nick)
if not var.OPT_IN_PING: if not var.OPT_IN_PING:
if not rest:
cli.notice(nick, "Please use {0}away and {0}back to mark yourself as away or back.".format(botconfig.CMD_CHAR)) cli.notice(nick, "Please use {0}away and {0}back to mark yourself as away or back.".format(botconfig.CMD_CHAR))
return return
if nick in var.USERS: if nick in var.USERS:
@ -694,6 +697,7 @@ def get_out(cli, nick, chan, rest):
"""Removes yourself from the ping list.""" """Removes yourself from the ping list."""
nick, _, _, cloak = parse_nick(nick) nick, _, _, cloak = parse_nick(nick)
if not var.OPT_IN_PING: if not var.OPT_IN_PING:
if not rest:
cli.notice(nick, "Please use {0}away and {0}back to mark yourself as away or back.".format(botconfig.CMD_CHAR)) cli.notice(nick, "Please use {0}away and {0}back to mark yourself as away or back.".format(botconfig.CMD_CHAR))
return return
if nick in var.USERS: if nick in var.USERS:
@ -3860,9 +3864,10 @@ def kill(cli, nick, chan, rest):
role = var.get_role(nick) role = var.get_role(nick)
except KeyError: except KeyError:
role = None role = None
if role in var.WOLFCHAT_ROLES and role not in ("wolf", "werecrow", "alpha wolf"): wolfroles = var.WOLF_ROLES - ["wolf cub"]
if role in var.WOLFCHAT_ROLES and role not in wolfroles:
return # they do this a lot. return # they do this a lot.
if role not in ("wolf", "werecrow", "alpha wolf", "hunter") and nick not in var.VENGEFUL_GHOSTS.keys(): if role not in wolfroles + ["hunter"] and nick not in var.VENGEFUL_GHOSTS.keys():
pm(cli, nick, "Only a wolf, hunter, or dead vengeful ghost may use this command.") pm(cli, nick, "Only a wolf, hunter, or dead vengeful ghost may use this command.")
return return
if var.PHASE != "night": if var.PHASE != "night":
@ -3875,13 +3880,13 @@ def kill(cli, nick, chan, rest):
if nick in var.SILENCED: if nick in var.SILENCED:
pm(cli, nick, "You have been silenced, and are unable to use any special powers.") pm(cli, nick, "You have been silenced, and are unable to use any special powers.")
return return
if role in ("wolf", "werecrow", "alpha wolf") and var.DISEASED_WOLVES: if role in wolfroles and var.DISEASED_WOLVES:
pm(cli, nick, "You are feeling ill, and are unable to kill anyone tonight.") pm(cli, nick, "You are feeling ill, and are unable to kill anyone tonight.")
return return
pieces = re.split(" +",rest) pieces = re.split(" +",rest)
victim = pieces[0] victim = pieces[0]
victim2 = None victim2 = None
if role in ("wolf", "werecrow", "alpha wolf") and var.ANGRY_WOLVES: if role in wolfroles and var.ANGRY_WOLVES:
if len(pieces) > 1: if len(pieces) > 1:
if len(pieces) > 2 and pieces[1].lower() == "and": if len(pieces) > 2 and pieces[1].lower() == "and":
victim2 = pieces[2] victim2 = pieces[2]
@ -3923,7 +3928,7 @@ def kill(cli, nick, chan, rest):
pm(cli, nick, "You must target a villager.") pm(cli, nick, "You must target a villager.")
return return
if role in ("wolf", "werecrow", "alpha wolf"): if role in wolfroles:
wolfchatwolves = var.list_players(var.WOLFCHAT_ROLES) wolfchatwolves = var.list_players(var.WOLFCHAT_ROLES)
if victim in wolfchatwolves or victim2 in wolfchatwolves: if victim in wolfchatwolves or victim2 in wolfchatwolves:
pm(cli, nick, "You may only kill villagers, not other wolves.") pm(cli, nick, "You may only kill villagers, not other wolves.")
@ -3964,7 +3969,7 @@ def kill(cli, nick, chan, rest):
else: else:
pm(cli, nick, "You have selected \u0002{0}\u0002 to be killed.".format(victim)) pm(cli, nick, "You have selected \u0002{0}\u0002 to be killed.".format(victim))
var.LOGGER.logBare(nick, "SELECT", victim) var.LOGGER.logBare(nick, "SELECT", victim)
if var.ANGRY_WOLVES and role in ("wolf", "werecrow", "alpha wolf"): if var.ANGRY_WOLVES and role in wolfroles:
pm(cli, nick, "You are angry tonight and may kill a second target. Use kill <nick1> and <nick2> to select multiple targets.") pm(cli, nick, "You are angry tonight and may kill a second target. Use kill <nick1> and <nick2> to select multiple targets.")
chk_nightdone(cli) chk_nightdone(cli)