bots: Switch TicTacToe to use state_handler.state() contextmanager.
@@ -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,
