zulip_bots: Make state_handler property of bot_handler.

This commit is contained in:
derAnfaenger 2017-10-23 12:17:46 +02:00
parent 45c38d0dcf
commit eb6982e670
25 changed files with 51 additions and 51 deletions

View file

@ -180,7 +180,7 @@ class CommuteHandler(object):
result = validate_requests(r)
return result
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content']
query = original_content.split()

View file

@ -46,7 +46,7 @@ class ConverterHandler(object):
all supported units.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
bot_response = get_bot_converter_response(message, bot_handler)
bot_handler.send_reply(message, bot_response)

View file

@ -23,7 +23,7 @@ class DefineHandler(object):
messages with @mention-bot.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content'].strip()
bot_response = self.get_bot_define_response(original_content)

View file

@ -28,7 +28,7 @@ class EncryptHandler(object):
Feeding encrypted messages into the bot decrypts them.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
bot_response = self.get_bot_encrypt_response(message)
bot_handler.send_reply(message, bot_response)

View file

@ -22,7 +22,7 @@ class FollowupHandler(object):
called "followup" that your API user can send to.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
if message['content'] == '':
bot_response = "Please specify the message you want to send to followup stream after @mention-bot"
bot_handler.send_reply(message, bot_response)

View file

@ -47,7 +47,7 @@ Example Inputs:
def send_info(self, message, letter, bot_handler):
bot_handler.send_reply(message, letter)
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
words = message['content'].split()
if "/help" in words:
self.send_info(message, self.help_info, bot_handler)

View file

@ -31,7 +31,7 @@ class GiphyHandler(object):
global config_info
config_info = bot_handler.get_config_info('giphy')
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
bot_response = get_bot_giphy_response(message, bot_handler)
bot_handler.send_reply(message, bot_response)

View file

@ -39,7 +39,7 @@ class GitHubHandler(object):
'<repository_owner>/<repository>/<issue_number>/<your_comment>'.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content']
original_sender = message['sender_email']

View file

@ -69,7 +69,7 @@ class GithubHandler(object):
repo = self.repo
return (owner, repo)
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
# type: () -> None
# Send help message
if message['content'] == 'help':

View file

@ -47,7 +47,7 @@ class IssueHandler(object):
github_token = <oauth_token> (The personal access token for the GitHub bot)
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content']
original_sender = message['sender_email']

View file

@ -72,7 +72,7 @@ class GoogleSearchHandler(object):
@mentioned-bot.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content']
result = get_google_result(original_content)
bot_handler.send_reply(message, result)

View file

@ -11,7 +11,7 @@ class HelloWorldHandler(object):
sophisticated, bots.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
content = 'beep boop'
bot_handler.send_reply(message, content)

View file

@ -11,7 +11,7 @@ class HelpHandler(object):
your Zulip instance.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
help_content = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip"
bot_handler.send_reply(message, help_content)

View file

@ -81,7 +81,7 @@ class HowdoiHandler(object):
return answer
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
question = message['content'].strip()
if question.startswith('howdowe!'):

View file

@ -11,8 +11,8 @@ class IncrementorHandler(object):
is @-mentioned, this number will be incremented in the same message.
'''
def handle_message(self, message, bot_handler, state_handler):
with state_handler.state({'number': 0, 'message_id': None}) as state:
def handle_message(self, message, bot_handler):
with bot_handler.state_handler.state({'number': 0, 'message_id': None}) as state:
state['number'] += 1
if state['message_id'] is None:
result = bot_handler.send_reply(message, str(state['number']))

View file

@ -103,7 +103,7 @@ class JohnHandler(object):
)
self.chatterbot = create_chat_bot(True)
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
original_content = message['content']
bot_response = str(self.chatterbot.get_response(original_content))
bot_handler.send_reply(message, bot_response)

View file

@ -274,14 +274,14 @@ class ticTacToeHandler(object):
message starts with @mention-bot.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
command_list = message['content']
command = ""
for val in command_list:
command += val
original_sender = message['sender_email']
with state_handler.state({}) as mydict:
with bot_handler.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))

View file

@ -7,7 +7,7 @@ class VirtualFsHandler(object):
def usage(self):
return get_help()
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
command = message['content']
if command == "":
command = "help"
@ -18,7 +18,7 @@ class VirtualFsHandler(object):
if isinstance(recipient, list): # If not a stream, then hash on list of emails
recipient = " ".join([x['email'] for x in recipient])
with state_handler.state({}) as state:
with bot_handler.state_handler.state({}) as state:
if recipient not in state:
state[recipient] = fs_new()
fs = state[recipient]

View file

@ -13,7 +13,7 @@ class WeatherHandler(object):
This plugin will give info about weather in a specified city
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
help_content = '''
This bot returns weather info for specified city.
You specify city in the following format:

View file

@ -32,7 +32,7 @@ class WikipediaHandler(object):
should preface searches with "@mention-bot".
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
bot_response = self.get_bot_wiki_response(message, bot_handler)
bot_handler.send_reply(message, bot_response)

View file

@ -32,7 +32,7 @@ class XkcdHandler(object):
`<comic_id>`, e.g `@mention-bot 1234`.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
xkcd_bot_response = get_xkcd_bot_response(message)
bot_handler.send_reply(message, xkcd_bot_response)

View file

@ -54,7 +54,7 @@ class YodaSpeakHandler(object):
@mention-bot You will learn how to speak like me someday.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
self.handle_input(message, bot_handler)
def send_to_yoda_api(self, sentence):

View file

@ -8,7 +8,7 @@ class YoutubeHandler(object):
This bot will return the first Youtube search result for the give query.
'''
def handle_message(self, message, bot_handler, state_handler):
def handle_message(self, message, bot_handler):
help_content = '''
To use the, Youtube Bot send `@mention-bot search terms`
Example: