From 7910d8767a38feedcdaa12838f1978d15a013f7c Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 30 Jun 2017 22:44:27 -0700 Subject: [PATCH] Bots: Adjust Incrementor bot to use StateHandler --- bots/incrementor/incrementor.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/bots/incrementor/incrementor.py b/bots/incrementor/incrementor.py index c498416..a9c6f44 100644 --- a/bots/incrementor/incrementor.py +++ b/bots/incrementor/incrementor.py @@ -3,10 +3,6 @@ class IncrementorHandler(object): - def __init__(self): - self.number = 0 - self.message_id = None - def usage(self): return ''' This is a boilerplate bot that makes use of the @@ -16,14 +12,17 @@ class IncrementorHandler(object): ''' def handle_message(self, message, bot_handler, state_handler): - self.number += 1 - if self.message_id is None: - result = bot_handler.send_reply(message, str(self.number)) - self.message_id = result['id'] + state = state_handler.get_state() or {'number': 0, 'message_id': None} + state['number'] += 1 + state_handler.set_state(state) + if state['message_id'] is None: + result = bot_handler.send_reply(message, str(state['number'])) + state['message_id'] = result['id'] + state_handler.set_state(state) else: bot_handler.update_message(dict( - message_id=self.message_id, - content=str(self.number), + message_id = state['message_id'], + content = str(state['number']) ))