bots: Switch TicTacToe to use state_handler.state() contextmanager.

This commit is contained in:
neiljp (Neil Pilgrim) 2017-07-23 13:22:54 -07:00 committed by Tim Abbott
parent 5ca9ec0771
commit 45527c4cf4

View file

@ -281,11 +281,7 @@ class ticTacToeHandler(object):
command += val
original_sender = message['sender_email']
mydict = state_handler.get_state()
if not mydict:
state_handler.set_state({})
mydict = state_handler.get_state()
with state_handler.state({}) as mydict:
user_game = mydict.get(original_sender)
if (not user_game) and command == "new":
user_game = TicTacToeGame(copy.deepcopy(initial_board))
@ -311,8 +307,6 @@ class ticTacToeHandler(object):
if "Game over" in return_content or "draw" in return_content:
del mydict[original_sender]
state_handler.set_state(mydict)
bot_handler.send_message(dict(
type = 'private',
to = original_sender,