bots: Switch Incrementor to use state_handler.state() contextmanager.
This commit is contained in:
parent
101dd60829
commit
7a8b41b63e
|
@ -12,18 +12,16 @@ class IncrementorHandler(object):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def handle_message(self, message, bot_handler, state_handler):
|
def handle_message(self, message, bot_handler, state_handler):
|
||||||
state = state_handler.get_state() or {'number': 0, 'message_id': None}
|
with state_handler.state({'number': 0, 'message_id': None}) as state:
|
||||||
state['number'] += 1
|
state['number'] += 1
|
||||||
state_handler.set_state(state)
|
if state['message_id'] is None:
|
||||||
if state['message_id'] is None:
|
result = bot_handler.send_reply(message, str(state['number']))
|
||||||
result = bot_handler.send_reply(message, str(state['number']))
|
state['message_id'] = result['id']
|
||||||
state['message_id'] = result['id']
|
else:
|
||||||
state_handler.set_state(state)
|
bot_handler.update_message(dict(
|
||||||
else:
|
message_id = state['message_id'],
|
||||||
bot_handler.update_message(dict(
|
content = str(state['number'])
|
||||||
message_id = state['message_id'],
|
))
|
||||||
content = str(state['number'])
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
handler_class = IncrementorHandler
|
handler_class = IncrementorHandler
|
||||||
|
|
Loading…
Reference in a new issue