From 246b9c22ae76fffaadb8fabe483e091b68e8a6d4 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 24 Jan 2020 10:18:33 -0800 Subject: [PATCH] Fix lexicon logs being overwritten by duplicate rw contexts --- amanuensis/lexicon/manage.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/amanuensis/lexicon/manage.py b/amanuensis/lexicon/manage.py index 237f4ae..1b2d849 100644 --- a/amanuensis/lexicon/manage.py +++ b/amanuensis/lexicon/manage.py @@ -145,11 +145,15 @@ def add_player(lex, player): raise ValueError("Invalid player: '{}'".format(player)) # Idempotently add player + added = False with json_rw(lex.config_path) as cfg: if player.id not in cfg.join.joined: cfg.join.joined.append(player.id) - # Log to the lexicon's log - lex.log("Player '{0.username}' joined ({0.id})".format(player)) + added = True + + # Log to the lexicon's log + if added: + lex.log("Player '{0.username}' joined ({0.id})".format(player)) def remove_player(lex, player): @@ -200,9 +204,14 @@ def add_character(lex, player, charinfo={}): character.signature = charinfo.get("signature") or ("~" + character.name) # Add the character to the lexicon + added = False with json_rw(lex.config_path) as cfg: 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): """