fix !swap and nick changing errors

var.ALL_PLAYERS update (for !swap) needs to happen before checking if the new user is in var.ALL_PLAYERS
pl is inaccurate during nick changes because the user's nick in var.ALL_PLAYERS is updated automatically but in var.ROLES isn't, therefore a user that changes nicks would never be returned in list_players()
one instance of prefix incorrectly changed to user.nick
This commit is contained in:
jacob1 2017-01-21 18:29:11 -05:00
parent 058acd40d7
commit 62f716093a

View File

@ -542,7 +542,7 @@ def replace(var, wrapper, message):
wrapper.pm(messages["already_playing"].format("You")) wrapper.pm(messages["already_playing"].format("You"))
return return
if temp.account is None: if wrapper.source.account is None:
wrapper.pm(messages["not_logged_in"]) wrapper.pm(messages["not_logged_in"])
return return
@ -3103,24 +3103,22 @@ 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 user in var.ALL_PLAYERS: try:
pl = list_players() temp = users._get(prefix) # FIXME
if user.nick in pl: except KeyError: # dirty hack; this isn't a swap
r = var.ROLES[get_role(user.nick)] pass
r.add(user.nick) else:
r.remove(prefix) # ALL_PLAYERS needs to keep its ordering for purposes of mad scientist
tpls = get_templates(prefix) var.ALL_PLAYERS[var.ALL_PLAYERS.index(temp)] = user
for t in tpls:
var.ROLES[t].add(user.nick)
var.ROLES[t].remove(prefix)
try: if user in var.ALL_PLAYERS:
temp = users._get(prefix) # FIXME r = var.ROLES[get_role(prefix)]
except KeyError: # dirty hack; this isn't a swap r.add(user.nick)
pass r.remove(prefix)
else: tpls = get_templates(prefix)
# ALL_PLAYERS needs to keep its ordering for purposes of mad scientist for t in tpls:
var.ALL_PLAYERS[var.ALL_PLAYERS.index(temp)] = user var.ROLES[t].add(user.nick)
var.ROLES[t].remove(prefix)
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():