From bd37161ece86ebbe5464e9e0d40f4fb7161c2d48 Mon Sep 17 00:00:00 2001 From: neiljp Date: Tue, 23 May 2017 12:00:30 -0700 Subject: [PATCH] Factor out send_reply functionality into bot_lib --- contrib_bots/bot_lib.py | 15 +++++++++++++++ contrib_bots/bots/wikipedia/wikipedia.py | 14 +------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/contrib_bots/bot_lib.py b/contrib_bots/bot_lib.py index ead1a53..6bbb55c 100644 --- a/contrib_bots/bot_lib.py +++ b/contrib_bots/bot_lib.py @@ -56,6 +56,21 @@ class BotHandlerApi(object): ' its own messages?') sys.exit(1) + def send_reply(self, message, response): + if message['type'] == 'private': + self.send_message(dict( + type='private', + to=[x['email'] for x in message['display_recipient'] if self.email != x['email']], + content=response, + )) + else: + self.send_message(dict( + type='stream', + to=message['display_recipient'], + subject=message['subject'], + content=response, + )) + def run_message_handler_for_bot(lib_module, quiet, config_file): # Make sure you set up your ~/.zuliprc client = Client(config_file=config_file) diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py index 64ef02c..3506232 100644 --- a/contrib_bots/bots/wikipedia/wikipedia.py +++ b/contrib_bots/bots/wikipedia/wikipedia.py @@ -28,19 +28,7 @@ class WikipediaHandler(object): def handle_message(self, message, client, state_handler): bot_response = self.get_bot_wiki_response(message, client) - if message['type'] == 'private': - client.send_message(dict( - type='private', - to=[x['email'] for x in message['display_recipient'] if client.email != x['email']], - content=bot_response, - )) - else: - client.send_message(dict( - type='stream', - to=message['display_recipient'], - subject=message['subject'], - content=bot_response, - )) + client.send_reply(message, bot_response) def get_bot_wiki_response(self, message, client): query = message['content']