2017-05-23 20:30:58 -04:00
|
|
|
# See readme.md for instructions on running this code.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
update_message function. For the first @-mention, it initially
|
|
|
|
replies with one message containing a `1`. Every time the bot
|
|
|
|
is @-mentioned, this number will be incremented in the same message.
|
|
|
|
'''
|
|
|
|
|
2017-06-11 09:03:39 -04:00
|
|
|
def handle_message(self, message, bot_handler, state_handler):
|
2017-05-23 20:30:58 -04:00
|
|
|
self.number += 1
|
|
|
|
if self.message_id is None:
|
2017-06-11 09:03:39 -04:00
|
|
|
result = bot_handler.send_reply(message, str(self.number))
|
2017-05-23 20:30:58 -04:00
|
|
|
self.message_id = result['id']
|
|
|
|
else:
|
2017-06-11 09:03:39 -04:00
|
|
|
bot_handler.update_message(dict(
|
2017-05-23 20:30:58 -04:00
|
|
|
message_id=self.message_id,
|
|
|
|
content=str(self.number),
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
handler_class = IncrementorHandler
|