Bots: Adjust Incrementor bot to use StateHandler
This commit is contained in:
parent
2645c97276
commit
7910d8767a
|
@ -3,10 +3,6 @@
|
||||||
|
|
||||||
class IncrementorHandler(object):
|
class IncrementorHandler(object):
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.number = 0
|
|
||||||
self.message_id = None
|
|
||||||
|
|
||||||
def usage(self):
|
def usage(self):
|
||||||
return '''
|
return '''
|
||||||
This is a boilerplate bot that makes use of the
|
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):
|
def handle_message(self, message, bot_handler, state_handler):
|
||||||
self.number += 1
|
state = state_handler.get_state() or {'number': 0, 'message_id': None}
|
||||||
if self.message_id is None:
|
state['number'] += 1
|
||||||
result = bot_handler.send_reply(message, str(self.number))
|
state_handler.set_state(state)
|
||||||
self.message_id = result['id']
|
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:
|
else:
|
||||||
bot_handler.update_message(dict(
|
bot_handler.update_message(dict(
|
||||||
message_id=self.message_id,
|
message_id = state['message_id'],
|
||||||
content=str(self.number),
|
content = str(state['number'])
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue