diff --git a/src/functions.py b/src/functions.py index 5f14942..dfccaba 100644 --- a/src/functions.py +++ b/src/functions.py @@ -3,7 +3,7 @@ from src.events import Event from src import settings as var from src import users -__all__ = ["get_players", "get_participants", "get_target", "get_role"] +__all__ = ["get_players", "get_participants", "get_target", "get_main_role", "get_all_roles"] def get_players(roles=None, *, mainroles=None): if mainroles is None: @@ -48,7 +48,7 @@ def get_target(var, wrapper, message, *, allow_self=False, allow_bot=False): return match -def get_role(user): +def get_main_role(user): role = var.MAIN_ROLES.get(user) if role is not None: return role @@ -60,3 +60,6 @@ def get_role(user): if role is None: raise ValueError("User {0} isn't playing and has no defined participant role".format(user)) return role + +def get_all_roles(user): + return {role for role, nicks in var.ROLES.items() if user.nick in nicks} diff --git a/src/handler.py b/src/handler.py index 07298d2..26bc904 100644 --- a/src/handler.py +++ b/src/handler.py @@ -12,7 +12,8 @@ import botconfig import src.settings as var from src import decorators, wolfgame, events, channels, hooks, users, errlog as log, stream_handler as alog from src.messages import messages -from src.utilities import reply, list_participants, get_role, get_templates +from src.utilities import reply, get_role, get_templates +from src.functions import get_participants from src.dispatcher import MessageDispatcher from src.decorators import handle_error @@ -67,7 +68,7 @@ def on_privmsg(cli, rawnick, chan, msg, *, notice=False, force_role=None): # as we don't want to insert bogus command keys into the dict. cmds = [] phase = var.PHASE - if user.nick in list_participants(): + if user in get_participants(): roles = {get_role(user.nick)} | set(get_templates(user.nick)) if force_role is not None: roles &= {force_role} # only fire off role commands for the forced role diff --git a/src/roles/vengefulghost.py b/src/roles/vengefulghost.py index ca17e2c..dd43794 100644 --- a/src/roles/vengefulghost.py +++ b/src/roles/vengefulghost.py @@ -60,10 +60,10 @@ def vg_retract(var, wrapper, message): del KILLS[wrapper.source.nick] wrapper.pm(messages["retracted_kill"]) -@event_listener("list_participants") -def on_list_participants(evt, var): - evt.data["pl"].extend([p.nick for p in GHOSTS if GHOSTS[p][0] != "!"]) - evt.data["pl"].extend([p.nick for p in drivenoff]) +@event_listener("get_participants") +def on_get_participants(evt, var): + evt.data["pl"].extend([p for p in GHOSTS if GHOSTS[p][0] != "!"]) + evt.data["pl"].extend(drivenoff) @event_listener("player_win", priority=1) def on_player_win(evt, var, user, role, winner, survived): diff --git a/src/utilities.py b/src/utilities.py index 61535b2..c037ade 100644 --- a/src/utilities.py +++ b/src/utilities.py @@ -13,7 +13,7 @@ __all__ = ["pm", "is_fake_nick", "mass_mode", "mass_privmsg", "reply", "relay_wolfchat_command", "chk_nightdone", "chk_decision", "chk_win", "irc_lower", "irc_equals", "is_role", "match_hostmask", "is_owner", "is_admin", "plural", "singular", "list_players", - "list_players_and_roles", "list_participants", "get_role", "get_roles", + "list_players_and_roles", "get_role", "get_roles", "get_reveal_role", "get_templates", "change_role", "role_order", "break_long_message", "complete_match","complete_one_match", "get_victim", "get_nick", "InvalidModeException"] # message either privmsg or notice, depending on user settings @@ -318,22 +318,16 @@ def list_players_and_roles(): # (and working with user objects instead of nicks) return {u.nick: r for u, r in var.MAIN_ROLES.items()} -def list_participants(): - """List all people who are still able to participate in the game in some fashion.""" - pl = list_players() - evt = Event("list_participants", {"pl": pl}) - evt.dispatch(var) - return evt.data["pl"][:] - def get_role(p): # FIXME: make the arg a user instead of a nick from src import users + from src.functions import get_participants user = users._get(p) role = var.MAIN_ROLES.get(user, None) if role is not None: return role # not found in player list, see if they're a special participant - if p in list_participants(): + if user in get_participants(): evt = Event("get_participant_role", {"role": None}) evt.dispatch(var, user) role = evt.data["role"] diff --git a/src/wolfgame.py b/src/wolfgame.py index 3db9198..935db44 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -49,7 +49,7 @@ import src.settings as var from src.utilities import * from src import db, events, dispatcher, channels, users, hooks, logger, proxy, debuglog, errlog, plog from src.decorators import command, cmd, hook, handle_error, event_listener, COMMANDS -from src.functions import get_players +from src.functions import get_players, get_participants from src.messages import messages from src.warnings import * from src.context import IRCContext @@ -552,7 +552,7 @@ def replace(var, wrapper, message): for user in var.ALL_PLAYERS: if users.equals(user.account, wrapper.source.account): - if user is wrapper.source or user.nick not in list_participants(): # FIXME: Need to fix once list_participants() holds User instances + if user is wrapper.source or user not in get_participants(): continue elif target is None: target = user @@ -565,7 +565,7 @@ def replace(var, wrapper, message): return else: - pl = [users._get(p) for p in list_participants()] # FIXME: Need to fix once list_participants() holds User instances + pl = get_participants() target, _ = users.complete_match(rest[0], pl) @@ -729,10 +729,10 @@ def join_deadchat(var, *all_users): return to_join = [] - pl = list_participants() + pl = get_participants() for user in all_users: - if user.stasis_count() or user.nick in pl or user in var.DEADCHAT_PLAYERS: # FIXME: Fix this when list_participants() returns User instances + if user.stasis_count() or user in pl or user in var.DEADCHAT_PLAYERS: continue to_join.append(user) @@ -6464,8 +6464,8 @@ def listroles(cli, nick, chan, rest): def myrole(cli, nick, chan, rest): # FIXME: Need to fix !swap once this gets converted """Reminds you of your current role.""" - ps = list_participants() - if nick not in ps: + ps = get_participants() + if users._get(nick) not in ps: return role = get_role(nick) @@ -6517,7 +6517,7 @@ def myrole(cli, nick, chan, rest): # FIXME: Need to fix !swap once this gets con pm(cli, nick, messages["prophet_simple"]) # Remind lovers of each other - if nick in ps and nick in var.LOVERS: + if users._get(nick) in ps and nick in var.LOVERS: message = messages["matched_info"] lovers = sorted(list(set(var.LOVERS[nick]))) if len(lovers) == 1: @@ -6899,9 +6899,9 @@ def can_run_restricted_cmd(user): if botconfig.DEBUG_MODE: return True - pl = list_participants() + pl = get_participants() - if user.nick in pl: # FIXME: Need to update this once list_participants() holds User instances + if user in pl: return False if not var.DISABLE_ACCOUNTS and user.account in [users._get(player).account for player in pl]: # FIXME