separate spectate into +p flag, add a notice when someone spectates wolf/deadchat

This commit is contained in:
jacob1 2017-11-05 00:15:24 -04:00
parent 33b2e26c15
commit cac3200164
3 changed files with 35 additions and 7 deletions

View File

@ -785,6 +785,7 @@
"fspectate_in_deadchat": "You are currently in deadchat.",
"fspectate_on": "You are now spectating {0}.",
"fspectate_off": "You are no longer spectating {0}.",
"fspectate_notice": "{0} is now spectating {1}.",
"maelstrom_dead": "You are dead and cannot join again.",
"villagergame_lose": "Game over! The villagers realize too late that there are actually no wolves, and never manage to rebuild to what they had before this fiasco. Nobody wins. (Hint: next time if you suspect there are no wolves, have everyone {0}vote {1}.)",
"villagergame_win": "Game over! The villagers come to their senses and realize there are actually no wolves, the previous deaths having been freak accidents. Everybody wins.",

View File

@ -89,6 +89,11 @@ AUTO_SANCTION = (
(20, 20, {"tempban": 10})
)
# Send a message to deadchat or wolfchat when a user spectates them
SPECTATE_NOTICE = True
# Whether to include which user is doing the spectating in the message
SPECTATE_NOTICE_USER = False
# The following is a bitfield, and they can be mixed together
# Defaults to none of these, can be changed on a per-game-mode basis
RESTRICT_WOLFCHAT = 0x00
@ -345,7 +350,7 @@ ROLE_COMMAND_EXCEPTIONS = set()
GIF_CHANCE = 1/50
ALL_FLAGS = frozenset("AaDdFgjmNSsw")
ALL_FLAGS = frozenset("AaDdFgjmNpSsw")
GRAVEYARD_LOCK = threading.RLock()
WARNING_LOCK = threading.RLock()

View File

@ -6908,9 +6908,7 @@ def can_run_restricted_cmd(user):
return True
@command("spectate", "fspectate", flag="a", pm=True, phases=("day", "night"))
def fspectate(var, wrapper, message):
"""Spectate wolfchat or deadchat."""
def spectate_chat(var, wrapper, message, spectate_warning):
if not can_run_restricted_cmd(wrapper.source):
wrapper.pm(messages["fspectate_restricted"])
return
@ -6936,19 +6934,43 @@ def fspectate(var, wrapper, message):
else:
players = []
if what == "wolfchat":
already_spectating = wrapper.source.nick in var.SPECTATING_WOLFCHAT
var.SPECTATING_WOLFCHAT.add(wrapper.source.nick)
players = [p for p in list_players() if in_wolflist(p, p)]
players = [p for p in get_players() if in_wolflist(p.nick, p.nick)]
if spectate_warning and not already_spectating and var.SPECTATE_NOTICE:
spectator = wrapper.source.nick if var.SPECTATE_NOTICE_USER else "Someone"
for player in players:
player.queue_message(messages["fspectate_notice"].format(spectator, what))
if players:
player.send_messages()
elif var.ENABLE_DEADCHAT:
already_spectating = wrapper.source in var.SPECTATING_DEADCHAT
if wrapper.source in var.DEADCHAT_PLAYERS:
wrapper.pm(messages["fspectate_in_deadchat"])
return
var.SPECTATING_DEADCHAT.add(wrapper.source)
players = [user.nick for user in var.DEADCHAT_PLAYERS]
players = var.DEADCHAT_PLAYERS
if spectate_warning and not already_spectating and var.SPECTATE_NOTICE:
spectator = wrapper.source.nick if var.SPECTATE_NOTICE_USER else "Someone"
for player in players:
player.queue_message(messages["fspectate_notice"].format(spectator, what))
if players:
player.send_messages()
else:
wrapper.pm(messages["fspectate_deadchat_disabled"])
return
wrapper.pm(messages["fspectate_on"].format(what))
wrapper.pm("People in {0}: {1}".format(what, ", ".join(players)))
wrapper.pm("People in {0}: {1}".format(what, ", ".join([player.nick for player in players])))
@command("spectate", flag="p", pm=True, phases=("day", "night"))
def fspectate(var, wrapper, message):
"""Spectate wolfchat or deadchat."""
spectate_chat(var, wrapper, message, True)
@command("fspectate", flag="F", pm=True, phases=("day", "night"))
def fspectate(var, wrapper, message):
"""Spectate wolfchat or deadchat."""
spectate_chat(var, wrapper, message, False)
@command("revealroles", flag="a", pm=True, phases=("day", "night"))
def revealroles(var, wrapper, message):