Fix lexicon logs being overwritten by duplicate rw contexts

This commit is contained in:
Tim Van Baak 2020-01-24 10:18:33 -08:00
parent a73f7b6cdc
commit 246b9c22ae
1 changed files with 11 additions and 2 deletions

View File

@ -145,11 +145,15 @@ def add_player(lex, player):
raise ValueError("Invalid player: '{}'".format(player)) raise ValueError("Invalid player: '{}'".format(player))
# Idempotently add player # Idempotently add player
added = False
with json_rw(lex.config_path) as cfg: with json_rw(lex.config_path) as cfg:
if player.id not in cfg.join.joined: if player.id not in cfg.join.joined:
cfg.join.joined.append(player.id) cfg.join.joined.append(player.id)
# Log to the lexicon's log added = True
lex.log("Player '{0.username}' joined ({0.id})".format(player))
# Log to the lexicon's log
if added:
lex.log("Player '{0.username}' joined ({0.id})".format(player))
def remove_player(lex, player): def remove_player(lex, player):
@ -200,9 +204,14 @@ def add_character(lex, player, charinfo={}):
character.signature = charinfo.get("signature") or ("~" + character.name) character.signature = charinfo.get("signature") or ("~" + character.name)
# Add the character to the lexicon # Add the character to the lexicon
added = False
with json_rw(lex.config_path) as cfg: with json_rw(lex.config_path) as cfg:
cfg.character.new(character.cid, character) cfg.character.new(character.cid, character)
added = True
# Log addition
if added:
lex.log("Character '{0.name}' created ({0.cid})".format(character))
def delete_character(lex, charname): def delete_character(lex, charname):
""" """