Change var.ALL_PLAYERS to hold User instances
Also some unrelated things
This commit is contained in:
parent
26fec0f5a0
commit
accba42ea2
@ -1206,7 +1206,7 @@ class MaelstromMode(GameMode):
|
|||||||
if var.PHASE != "day" or (wrapper.public and wrapper.target is not channels.Main):
|
if var.PHASE != "day" or (wrapper.public and wrapper.target is not channels.Main):
|
||||||
return
|
return
|
||||||
temp = wrapper.source.lower()
|
temp = wrapper.source.lower()
|
||||||
if (temp.nick in (irc_lower(x) for x in var.ALL_PLAYERS) or # FIXME
|
if (wrapper.source in var.ALL_PLAYERS or
|
||||||
temp.account in self.DEAD_ACCOUNTS or
|
temp.account in self.DEAD_ACCOUNTS or
|
||||||
temp.host in self.DEAD_HOSTS):
|
temp.host in self.DEAD_HOSTS):
|
||||||
wrapper.pm(messages["maelstrom_dead"])
|
wrapper.pm(messages["maelstrom_dead"])
|
||||||
|
@ -318,7 +318,7 @@ def list_players(roles=None):
|
|||||||
continue
|
continue
|
||||||
for p in var.ROLES.get(x, ()):
|
for p in var.ROLES.get(x, ()):
|
||||||
pl.add(p)
|
pl.add(p)
|
||||||
return [p for p in var.ALL_PLAYERS if p in pl]
|
return [p.nick for p in var.ALL_PLAYERS if p.nick in pl]
|
||||||
|
|
||||||
def list_players_and_roles():
|
def list_players_and_roles():
|
||||||
plr = {}
|
plr = {}
|
||||||
|
@ -857,7 +857,7 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True):
|
|||||||
users.get(wrapper.source.nick).moded.update(users.get(wrapper.source.nick).modes)
|
users.get(wrapper.source.nick).moded.update(users.get(wrapper.source.nick).modes)
|
||||||
users.get(wrapper.source.nick).modes.clear()
|
users.get(wrapper.source.nick).modes.clear()
|
||||||
var.ROLES["person"].add(wrapper.source.nick) # FIXME: Need to store Users, not nicks
|
var.ROLES["person"].add(wrapper.source.nick) # FIXME: Need to store Users, not nicks
|
||||||
var.ALL_PLAYERS.append(wrapper.source.nick)
|
var.ALL_PLAYERS.append(wrapper.source)
|
||||||
var.PHASE = "join"
|
var.PHASE = "join"
|
||||||
with var.WAIT_TB_LOCK:
|
with var.WAIT_TB_LOCK:
|
||||||
var.WAIT_TB_TOKENS = var.WAIT_TB_INIT
|
var.WAIT_TB_TOKENS = var.WAIT_TB_INIT
|
||||||
@ -874,7 +874,7 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True):
|
|||||||
|
|
||||||
# Set join timer
|
# Set join timer
|
||||||
if var.JOIN_TIME_LIMIT > 0:
|
if var.JOIN_TIME_LIMIT > 0:
|
||||||
t = threading.Timer(var.JOIN_TIME_LIMIT, kill_join, [wrapper.source.client, wrapper.target.name])
|
t = threading.Timer(var.JOIN_TIME_LIMIT, kill_join, [var, wrapper])
|
||||||
var.TIMERS["join"] = (t, time.time(), var.JOIN_TIME_LIMIT)
|
var.TIMERS["join"] = (t, time.time(), var.JOIN_TIME_LIMIT)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
@ -902,7 +902,7 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True):
|
|||||||
who.send(msg.format(who, "their", ""), notice=True)
|
who.send(msg.format(who, "their", ""), notice=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
var.ALL_PLAYERS.append(wrapper.source.nick)
|
var.ALL_PLAYERS.append(wrapper.source)
|
||||||
if not wrapper.source.is_fake or not botconfig.DEBUG_MODE:
|
if not wrapper.source.is_fake or not botconfig.DEBUG_MODE:
|
||||||
if var.AUTO_TOGGLE_MODES and users.get(wrapper.source.nick).modes:
|
if var.AUTO_TOGGLE_MODES and users.get(wrapper.source.nick).modes:
|
||||||
for mode in users.get(wrapper.source.nick).modes:
|
for mode in users.get(wrapper.source.nick).modes:
|
||||||
@ -954,14 +954,14 @@ def join_player(var, wrapper, who=None, forced=False, *, sanity=True):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@handle_error
|
@handle_error
|
||||||
def kill_join(cli, chan):
|
def kill_join(var, wrapper):
|
||||||
pl = list_players()
|
pl = list_players()
|
||||||
pl.sort(key=lambda x: x.lower())
|
pl.sort(key=lambda x: x.lower())
|
||||||
msg = "PING! " + break_long_message(pl).replace("\n", "\nPING! ")
|
msg = "PING! " + break_long_message(pl).replace("\n", "\nPING! ")
|
||||||
reset_modes_timers(cli)
|
reset_modes_timers(wrapper.client)
|
||||||
reset()
|
reset()
|
||||||
cli.msg(chan, msg)
|
wrapper.send(*pl, first="PING! ")
|
||||||
cli.msg(chan, messages["game_idle_cancel"])
|
wrapper.send(messages["game_idle_cancel"])
|
||||||
# use this opportunity to expire pending stasis
|
# use this opportunity to expire pending stasis
|
||||||
db.expire_stasis()
|
db.expire_stasis()
|
||||||
db.init_vars()
|
db.init_vars()
|
||||||
@ -970,7 +970,6 @@ def kill_join(cli, chan):
|
|||||||
var.AFTER_FLASTGAME()
|
var.AFTER_FLASTGAME()
|
||||||
var.AFTER_FLASTGAME = None
|
var.AFTER_FLASTGAME = None
|
||||||
|
|
||||||
|
|
||||||
@command("fjoin", flag="A")
|
@command("fjoin", flag="A")
|
||||||
def fjoin(var, wrapper, message):
|
def fjoin(var, wrapper, message):
|
||||||
"""Forces someone to join a game."""
|
"""Forces someone to join a game."""
|
||||||
@ -998,7 +997,6 @@ def fjoin(var, wrapper, message):
|
|||||||
fake = True
|
fake = True
|
||||||
for i in range(int(first), int(last)+1):
|
for i in range(int(first), int(last)+1):
|
||||||
user = users._add(wrapper.source.client, nick=str(i)) # FIXME
|
user = users._add(wrapper.source.client, nick=str(i)) # FIXME
|
||||||
channels.Dummy.users.add(user) # keep a strong reference to fake users (this will be removed eventually)
|
|
||||||
evt.data["join_player"](var, type(wrapper)(user, wrapper.target), forced=True, who=wrapper.source)
|
evt.data["join_player"](var, type(wrapper)(user, wrapper.target), forced=True, who=wrapper.source)
|
||||||
continue
|
continue
|
||||||
if not tojoin:
|
if not tojoin:
|
||||||
@ -1298,6 +1296,7 @@ def stats(cli, nick, chan, rest):
|
|||||||
# Step 4. Remove all dead players
|
# Step 4. Remove all dead players
|
||||||
# When rolesets are a thing (e.g. one of x, y, or z), those will be resolved here as well
|
# When rolesets are a thing (e.g. one of x, y, or z), those will be resolved here as well
|
||||||
for p in var.ALL_PLAYERS:
|
for p in var.ALL_PLAYERS:
|
||||||
|
p = p.nick # FIXME: Need to modify this block to handle User instances
|
||||||
if p in pl:
|
if p in pl:
|
||||||
continue
|
continue
|
||||||
# pr should be the role the person gets revealed as should they die
|
# pr should be the role the person gets revealed as should they die
|
||||||
@ -2660,7 +2659,9 @@ def del_player(cli, nick, forced_death=False, devoice=True, end_game=True, death
|
|||||||
if nickrole == "mad scientist":
|
if nickrole == "mad scientist":
|
||||||
# kills the 2 players adjacent to them in the original players listing (in order of !joining)
|
# kills the 2 players adjacent to them in the original players listing (in order of !joining)
|
||||||
# if those players are already dead, nothing happens
|
# if those players are already dead, nothing happens
|
||||||
index = var.ALL_PLAYERS.index(nick)
|
for index, user in enumerate(var.ALL_PLAYERS):
|
||||||
|
if user.nick == nick: # FIXME
|
||||||
|
break
|
||||||
targets = []
|
targets = []
|
||||||
target1 = var.ALL_PLAYERS[index - 1]
|
target1 = var.ALL_PLAYERS[index - 1]
|
||||||
target2 = var.ALL_PLAYERS[index + 1 if index < len(var.ALL_PLAYERS) - 1 else 0]
|
target2 = var.ALL_PLAYERS[index + 1 if index < len(var.ALL_PLAYERS) - 1 else 0]
|
||||||
@ -2669,9 +2670,7 @@ def del_player(cli, nick, forced_death=False, devoice=True, end_game=True, death
|
|||||||
i = index
|
i = index
|
||||||
while True:
|
while True:
|
||||||
i -= 1
|
i -= 1
|
||||||
if i < 0:
|
if var.ALL_PLAYERS[i].nick in pl or var.ALL_PLAYERS[i].nick == nick:
|
||||||
i = len(var.ALL_PLAYERS) - 1
|
|
||||||
if var.ALL_PLAYERS[i] in pl or var.ALL_PLAYERS[i] == nick:
|
|
||||||
target1 = var.ALL_PLAYERS[i]
|
target1 = var.ALL_PLAYERS[i]
|
||||||
break
|
break
|
||||||
# determine right player
|
# determine right player
|
||||||
@ -2680,14 +2679,14 @@ def del_player(cli, nick, forced_death=False, devoice=True, end_game=True, death
|
|||||||
i += 1
|
i += 1
|
||||||
if i >= len(var.ALL_PLAYERS):
|
if i >= len(var.ALL_PLAYERS):
|
||||||
i = 0
|
i = 0
|
||||||
if var.ALL_PLAYERS[i] in pl or var.ALL_PLAYERS[i] == nick:
|
if var.ALL_PLAYERS[i].nick in pl or var.ALL_PLAYERS[i].nick == nick:
|
||||||
target2 = var.ALL_PLAYERS[i]
|
target2 = var.ALL_PLAYERS[i]
|
||||||
break
|
break
|
||||||
|
|
||||||
# do not kill blessed players, they had a premonition to step out of the way before the chemicals hit
|
# do not kill blessed players, they had a premonition to step out of the way before the chemicals hit
|
||||||
if target1 in var.ROLES["blessed villager"]:
|
if target1.nick in var.ROLES["blessed villager"]:
|
||||||
target1 = None
|
target1 = None
|
||||||
if target2 in var.ROLES["blessed villager"]:
|
if target2.nick in var.ROLES["blessed villager"]:
|
||||||
target2 = None
|
target2 = None
|
||||||
|
|
||||||
if target1 in pl:
|
if target1 in pl:
|
||||||
@ -2804,7 +2803,7 @@ def del_player(cli, nick, forced_death=False, devoice=True, end_game=True, death
|
|||||||
cmode.append(("+"+newmode, nick))
|
cmode.append(("+"+newmode, nick))
|
||||||
users.get(nick).modes.update(users.get(nick).moded)
|
users.get(nick).modes.update(users.get(nick).moded)
|
||||||
users.get(nick).moded = set()
|
users.get(nick).moded = set()
|
||||||
var.ALL_PLAYERS.remove(nick)
|
var.ALL_PLAYERS.remove(users._get(nick)) # FIXME
|
||||||
ret = not chk_win(cli)
|
ret = not chk_win(cli)
|
||||||
else:
|
else:
|
||||||
# Died during the game, so quiet!
|
# Died during the game, so quiet!
|
||||||
@ -3103,19 +3102,19 @@ def rename_player(var, user, prefix):
|
|||||||
event = Event("rename_player", {})
|
event = Event("rename_player", {})
|
||||||
event.dispatch(user.client, var, prefix, nick) # FIXME: Need to update all the callbacks
|
event.dispatch(user.client, var, prefix, nick) # FIXME: Need to update all the callbacks
|
||||||
|
|
||||||
if prefix in var.ALL_PLAYERS:
|
if user in var.ALL_PLAYERS:
|
||||||
pl = list_players()
|
pl = list_players()
|
||||||
if prefix in pl:
|
if user.nick in pl:
|
||||||
r = var.ROLES[get_role(prefix)]
|
r = var.ROLES[get_role(user.nick)]
|
||||||
r.add(nick)
|
r.add(user.nick)
|
||||||
r.remove(prefix)
|
r.remove(prefix)
|
||||||
tpls = get_templates(prefix)
|
tpls = get_templates(prefix)
|
||||||
for t in tpls:
|
for t in tpls:
|
||||||
var.ROLES[t].add(nick)
|
var.ROLES[t].add(user.nick)
|
||||||
var.ROLES[t].remove(prefix)
|
var.ROLES[t].remove(prefix)
|
||||||
|
|
||||||
# ALL_PLAYERS needs to keep its ordering for purposes of mad scientist
|
# ALL_PLAYERS needs to keep its ordering for purposes of mad scientist
|
||||||
var.ALL_PLAYERS[var.ALL_PLAYERS.index(prefix)] = nick
|
var.ALL_PLAYERS[var.ALL_PLAYERS.index(users._get(prefix))] = user # FIXME
|
||||||
|
|
||||||
if var.PHASE in var.GAME_PHASES:
|
if var.PHASE in var.GAME_PHASES:
|
||||||
for k,v in var.ORIGINAL_ROLES.items():
|
for k,v in var.ORIGINAL_ROLES.items():
|
||||||
@ -4162,15 +4161,15 @@ def lynch(cli, nick, chan, rest):
|
|||||||
def choose_target(actor, nick):
|
def choose_target(actor, nick):
|
||||||
pl = list_players()
|
pl = list_players()
|
||||||
if actor in var.MISDIRECTED:
|
if actor in var.MISDIRECTED:
|
||||||
i = var.ALL_PLAYERS.index(nick)
|
for i, user in enumerate(var.ALL_PLAYERS):
|
||||||
|
if user.nick == nick:
|
||||||
|
break
|
||||||
if random.randint(0, 1) == 0:
|
if random.randint(0, 1) == 0:
|
||||||
# going left
|
# going left
|
||||||
while True:
|
while True:
|
||||||
i -= 1
|
i -= 1
|
||||||
if i < 0:
|
if var.ALL_PLAYERS[i].nick in pl:
|
||||||
i = len(var.ALL_PLAYERS) - 1
|
nick = var.ALL_PLAYERS[i].nick
|
||||||
if var.ALL_PLAYERS[i] in pl:
|
|
||||||
nick = var.ALL_PLAYERS[i]
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# going right
|
# going right
|
||||||
@ -4178,19 +4177,19 @@ def choose_target(actor, nick):
|
|||||||
i += 1
|
i += 1
|
||||||
if i >= len(var.ALL_PLAYERS):
|
if i >= len(var.ALL_PLAYERS):
|
||||||
i = 0
|
i = 0
|
||||||
if var.ALL_PLAYERS[i] in pl:
|
if var.ALL_PLAYERS[i].nick in pl:
|
||||||
nick = var.ALL_PLAYERS[i]
|
nick = var.ALL_PLAYERS[i].nick
|
||||||
break
|
break
|
||||||
if nick in var.LUCKY:
|
if nick in var.LUCKY:
|
||||||
i = var.ALL_PLAYERS.index(nick)
|
for i, user in enumerate(var.ALL_PLAYERS):
|
||||||
|
if user.nick == nick:
|
||||||
|
break
|
||||||
if random.randint(0, 1) == 0:
|
if random.randint(0, 1) == 0:
|
||||||
# going left
|
# going left
|
||||||
while True:
|
while True:
|
||||||
i -= 1
|
i -= 1
|
||||||
if i < 0:
|
if var.ALL_PLAYERS[i].nick in pl:
|
||||||
i = len(var.ALL_PLAYERS) - 1
|
nick = var.ALL_PLAYERS[i].nick
|
||||||
if var.ALL_PLAYERS[i] in pl:
|
|
||||||
nick = var.ALL_PLAYERS[i]
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# going right
|
# going right
|
||||||
@ -4198,8 +4197,8 @@ def choose_target(actor, nick):
|
|||||||
i += 1
|
i += 1
|
||||||
if i >= len(var.ALL_PLAYERS):
|
if i >= len(var.ALL_PLAYERS):
|
||||||
i = 0
|
i = 0
|
||||||
if var.ALL_PLAYERS[i] in pl:
|
if var.ALL_PLAYERS[i].nick in pl:
|
||||||
nick = var.ALL_PLAYERS[i]
|
nick = var.ALL_PLAYERS[i].nick
|
||||||
break
|
break
|
||||||
return nick
|
return nick
|
||||||
|
|
||||||
@ -4556,7 +4555,7 @@ def consecrate(cli, nick, chan, rest):
|
|||||||
if not victim:
|
if not victim:
|
||||||
pm(cli, nick, messages["not_enough_parameters"])
|
pm(cli, nick, messages["not_enough_parameters"])
|
||||||
return
|
return
|
||||||
dead = [x for x in var.ALL_PLAYERS if x not in alive]
|
dead = [x.nick for x in var.ALL_PLAYERS if x.nick not in alive]
|
||||||
deadl = [x.lower() for x in dead]
|
deadl = [x.lower() for x in dead]
|
||||||
|
|
||||||
tempvictim, num_matches = complete_match(victim.lower(), deadl)
|
tempvictim, num_matches = complete_match(victim.lower(), deadl)
|
||||||
@ -5545,7 +5544,9 @@ def transition_night(cli):
|
|||||||
|
|
||||||
for ms in var.ROLES["mad scientist"]:
|
for ms in var.ROLES["mad scientist"]:
|
||||||
pl = ps[:]
|
pl = ps[:]
|
||||||
index = var.ALL_PLAYERS.index(ms)
|
for index, user in enumerate(var.ALL_PLAYERS):
|
||||||
|
if user.nick == ms:
|
||||||
|
break
|
||||||
targets = []
|
targets = []
|
||||||
target1 = var.ALL_PLAYERS[index - 1]
|
target1 = var.ALL_PLAYERS[index - 1]
|
||||||
target2 = var.ALL_PLAYERS[index + 1 if index < len(var.ALL_PLAYERS) - 1 else 0]
|
target2 = var.ALL_PLAYERS[index + 1 if index < len(var.ALL_PLAYERS) - 1 else 0]
|
||||||
@ -5554,9 +5555,7 @@ def transition_night(cli):
|
|||||||
i = index
|
i = index
|
||||||
while True:
|
while True:
|
||||||
i -= 1
|
i -= 1
|
||||||
if i < 0:
|
if var.ALL_PLAYERS[i].nick in pl or var.ALL_PLAYERS[i].nick == ms:
|
||||||
i = len(var.ALL_PLAYERS) - 1
|
|
||||||
if var.ALL_PLAYERS[i] in pl or var.ALL_PLAYERS[i] == ms:
|
|
||||||
target1 = var.ALL_PLAYERS[i]
|
target1 = var.ALL_PLAYERS[i]
|
||||||
break
|
break
|
||||||
# determine right player
|
# determine right player
|
||||||
@ -5565,7 +5564,7 @@ def transition_night(cli):
|
|||||||
i += 1
|
i += 1
|
||||||
if i >= len(var.ALL_PLAYERS):
|
if i >= len(var.ALL_PLAYERS):
|
||||||
i = 0
|
i = 0
|
||||||
if var.ALL_PLAYERS[i] in pl or var.ALL_PLAYERS[i] == ms:
|
if var.ALL_PLAYERS[i].nick in pl or var.ALL_PLAYERS[i].nick == ms:
|
||||||
target2 = var.ALL_PLAYERS[i]
|
target2 = var.ALL_PLAYERS[i]
|
||||||
break
|
break
|
||||||
if ms in var.PLAYERS and not is_user_simple(ms):
|
if ms in var.PLAYERS and not is_user_simple(ms):
|
||||||
@ -6020,7 +6019,7 @@ def start(cli, nick, chan, forced = False, restart = ""):
|
|||||||
if len(possible) < len(var.ROLES[template]):
|
if len(possible) < len(var.ROLES[template]):
|
||||||
cli.msg(chan, messages["not_enough_targets"].format(template))
|
cli.msg(chan, messages["not_enough_targets"].format(template))
|
||||||
if var.ORIGINAL_SETTINGS:
|
if var.ORIGINAL_SETTINGS:
|
||||||
var.ROLES = {"person": var.ALL_PLAYERS}
|
var.ROLES = {"person": {x.nick for x in var.ALL_PLAYERS}}
|
||||||
reset_settings()
|
reset_settings()
|
||||||
cli.msg(chan, messages["default_reset"].format(botconfig.CMD_CHAR))
|
cli.msg(chan, messages["default_reset"].format(botconfig.CMD_CHAR))
|
||||||
var.PHASE = "join"
|
var.PHASE = "join"
|
||||||
@ -7511,7 +7510,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
|
|||||||
var.GUNNERS[who] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
var.GUNNERS[who] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
||||||
if who not in pl:
|
if who not in pl:
|
||||||
var.ROLES[var.DEFAULT_ROLE].add(who)
|
var.ROLES[var.DEFAULT_ROLE].add(who)
|
||||||
var.ALL_PLAYERS.append(who)
|
var.ALL_PLAYERS.append(users._get(who)) # FIXME
|
||||||
if not is_fake_nick(who):
|
if not is_fake_nick(who):
|
||||||
cli.mode(chan, "+v", who)
|
cli.mode(chan, "+v", who)
|
||||||
cli.msg(chan, messages["template_default_role"].format(var.DEFAULT_ROLE))
|
cli.msg(chan, messages["template_default_role"].format(var.DEFAULT_ROLE))
|
||||||
@ -7537,7 +7536,7 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
|
|||||||
oldrole = get_role(who)
|
oldrole = get_role(who)
|
||||||
var.ROLES[oldrole].remove(who)
|
var.ROLES[oldrole].remove(who)
|
||||||
else:
|
else:
|
||||||
var.ALL_PLAYERS.append(who)
|
var.ALL_PLAYERS.append(users._get(who)) # FIXME
|
||||||
var.ROLES[rol].add(who)
|
var.ROLES[rol].add(who)
|
||||||
if who not in pl:
|
if who not in pl:
|
||||||
var.ORIGINAL_ROLES[rol].add(who)
|
var.ORIGINAL_ROLES[rol].add(who)
|
||||||
|
Loading…
Reference in New Issue
Block a user