From cac320016400227616047ef70bda39be258739bc Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 5 Nov 2017 00:15:24 -0400 Subject: [PATCH 1/2] separate spectate into +p flag, add a notice when someone spectates wolf/deadchat --- messages/en.json | 1 + src/settings.py | 7 ++++++- src/wolfgame.py | 34 ++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/messages/en.json b/messages/en.json index eb66b31..7e00ee7 100644 --- a/messages/en.json +++ b/messages/en.json @@ -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.", diff --git a/src/settings.py b/src/settings.py index c4d7f25..e8b90b1 100644 --- a/src/settings.py +++ b/src/settings.py @@ -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() diff --git a/src/wolfgame.py b/src/wolfgame.py index 96cc55a..43c80a4 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -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): From 7a003e4cb7a575be01fe421c72f9d697e9f8ecc7 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 5 Nov 2017 20:11:05 -0500 Subject: [PATCH 2/2] convert var.SPECTATING_WOLFCHAT to users, prevent !spectate deadchat --- messages/en.json | 1 + src/utilities.py | 5 ++++- src/wolfgame.py | 47 +++++++++++++++++++++-------------------------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/messages/en.json b/messages/en.json index 7e00ee7..cca1491 100644 --- a/messages/en.json +++ b/messages/en.json @@ -779,6 +779,7 @@ "already_up_to_date": "Already up-to-date.", "admin_fleave_deadchat": "You have forced {0} to leave the deadchat.", "available_mode_setters_help": "Votes to make a specific game mode more likely. Available game mode setters: ", + "spectate_help": "Usage: spectate [on|off]", "fspectate_help": "Usage: fspectate [on|off]", "fspectate_restricted": "You may not spectate while playing.", "fspectate_deadchat_disabled": "Deadchat is disabled and may not be spectated.", diff --git a/src/utilities.py b/src/utilities.py index c037ade..2c9f3ad 100644 --- a/src/utilities.py +++ b/src/utilities.py @@ -170,7 +170,10 @@ def relay_wolfchat_command(cli, nick, message, roles, is_wolf_command=False, is_ wcwolves = list_players(wcroles) wcwolves.remove(nick) mass_privmsg(cli, wcwolves, message) - mass_privmsg(cli, var.SPECTATING_WOLFCHAT, "[wolfchat] " + message) + for player in var.SPECTATING_WOLFCHAT: + player.queue_message("[wolfchat] " + message) + if var.SPECTATING_WOLFCHAT: + player.send_messages() @proxy.stub def chk_nightdone(cli): diff --git a/src/wolfgame.py b/src/wolfgame.py index 43c80a4..3cb92d7 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -924,7 +924,7 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True): # Abandon Hope All Ye Who Enter Here leave_deadchat(var, wrapper.source) var.SPECTATING_DEADCHAT.discard(wrapper.source) - var.SPECTATING_WOLFCHAT.discard(wrapper.source.nick) + var.SPECTATING_WOLFCHAT.discard(wrapper.source) return True var.ROLES["person"].add(wrapper.source.nick) var.MAIN_ROLES[wrapper.source] = "person" @@ -2959,11 +2959,6 @@ def return_to_village(var, chan, target, *, show_message): def rename_player(var, user, prefix): nick = user.nick - if var.PHASE in var.GAME_PHASES: - if prefix in var.SPECTATING_WOLFCHAT: - var.SPECTATING_WOLFCHAT.remove(prefix) - var.SPECTATING_WOLFCHAT.add(nick) - event = Event("rename_player", {}) event.dispatch(user.client, var, prefix, nick) # FIXME: Need to update all the callbacks @@ -3220,7 +3215,7 @@ def leave(var, what, user, why=None): killplayer = False channels.Main.send(msg.format(user, get_reveal_role(user.nick)) + population) # FIXME: Need to fix this once get_reveal_role() accepts User instances - var.SPECTATING_WOLFCHAT.discard(user.nick) # FIXME: Need to fix this once the variable holds User instances + var.SPECTATING_WOLFCHAT.discard(user) var.SPECTATING_DEADCHAT.discard(user) leave_deadchat(var, user) @@ -5128,10 +5123,16 @@ def relay(var, wrapper, message): if message.startswith("\u0001ACTION"): message = message[7:-1] mass_privmsg(wrapper.client, to_msg, "* \u0002{0}\u0002{1}".format(wrapper.source, message)) - mass_privmsg(wrapper.client, var.SPECTATING_WOLFCHAT, "* [wolfchat] \u0002{0}\u0002{1}".format(wrapper.source, message)) + for player in var.SPECTATING_WOLFCHAT: + player.queue_message("* [wolfchat] \u0002{0}\u0002{1}".format(wrapper.source, message)) + if var.SPECTATING_WOLFCHAT: + player.send_messages() else: mass_privmsg(wrapper.client, to_msg, "\u0002{0}\u0002 says: {1}".format(wrapper.source, message)) - mass_privmsg(wrapper.client, var.SPECTATING_WOLFCHAT, "[wolfchat] \u0002{0}\u0002 says: {1}".format(wrapper.source, message)) + for player in var.SPECTATING_WOLFCHAT: + player.queue_message("[wolfchat] \u0002{0}\u0002 says: {1}".format(wrapper.source, message)) + if var.SPECTATING_WOLFCHAT: + player.send_messages() @handle_error def transition_night(cli): @@ -6908,7 +6909,7 @@ def can_run_restricted_cmd(user): return True -def spectate_chat(var, wrapper, message, spectate_warning): +def spectate_chat(var, wrapper, message, *, is_fspectate): if not can_run_restricted_cmd(wrapper.source): wrapper.pm(messages["fspectate_restricted"]) return @@ -6921,41 +6922,35 @@ def spectate_chat(var, wrapper, message, spectate_warning): elif len(params) > 1: on = params[1].lower() what = params[0].lower() - if what not in ("wolfchat", "deadchat") or on not in ("on", "off"): - wrapper.pm(messages["fspectate_help"]) + allowed = ("wolfchat", "deadchat") if is_fspectate else ("wolfchat",) + if what not in allowed or on not in ("on", "off"): + wrapper.pm(messages["fspectate_help" if is_fspectate else "spectate_help"]) return if on == "off": if what == "wolfchat": - var.SPECTATING_WOLFCHAT.discard(wrapper.source.nick) + var.SPECTATING_WOLFCHAT.discard(wrapper.source) else: var.SPECTATING_DEADCHAT.discard(wrapper.source) wrapper.pm(messages["fspectate_off"].format(what)) else: players = [] if what == "wolfchat": - already_spectating = wrapper.source.nick in var.SPECTATING_WOLFCHAT - var.SPECTATING_WOLFCHAT.add(wrapper.source.nick) + already_spectating = wrapper.source in var.SPECTATING_WOLFCHAT + var.SPECTATING_WOLFCHAT.add(wrapper.source) 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: + if not is_fspectate 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 = 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 @@ -6963,14 +6958,14 @@ def spectate_chat(var, wrapper, message, spectate_warning): 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): +def spectate(var, wrapper, message): """Spectate wolfchat or deadchat.""" - spectate_chat(var, wrapper, message, True) + spectate_chat(var, wrapper, message, is_fspectate=False) @command("fspectate", flag="F", pm=True, phases=("day", "night")) def fspectate(var, wrapper, message): """Spectate wolfchat or deadchat.""" - spectate_chat(var, wrapper, message, False) + spectate_chat(var, wrapper, message, is_fspectate=True) @command("revealroles", flag="a", pm=True, phases=("day", "night")) def revealroles(var, wrapper, message):