Factor out send_reply functionality into bot_lib

This commit is contained in:
neiljp 2017-05-23 12:00:30 -07:00 committed by Tim Abbott
parent 5252626095
commit bd37161ece
2 changed files with 16 additions and 13 deletions

View file

@ -56,6 +56,21 @@ class BotHandlerApi(object):
' its own messages?') ' its own messages?')
sys.exit(1) 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): def run_message_handler_for_bot(lib_module, quiet, config_file):
# Make sure you set up your ~/.zuliprc # Make sure you set up your ~/.zuliprc
client = Client(config_file=config_file) client = Client(config_file=config_file)

View file

@ -28,19 +28,7 @@ class WikipediaHandler(object):
def handle_message(self, message, client, state_handler): def handle_message(self, message, client, state_handler):
bot_response = self.get_bot_wiki_response(message, client) bot_response = self.get_bot_wiki_response(message, client)
if message['type'] == 'private': client.send_reply(message, bot_response)
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,
))
def get_bot_wiki_response(self, message, client): def get_bot_wiki_response(self, message, client):
query = message['content'] query = message['content']