bots: Clean up terminal.py for running bots directly.

Make terminal.py exit gracefully with a message.
Modify output bot reply for better understanding in multi-line
output.
This commit is contained in:
Abhijeet Kaur 2017-11-29 02:46:35 +05:30 committed by showell
parent 353475f245
commit 91c4ff668d
2 changed files with 18 additions and 15 deletions

View file

@ -1,4 +1,5 @@
import configparser import configparser
import sys
class SimpleStorage: class SimpleStorage:
def __init__(self): def __init__(self):
@ -49,10 +50,7 @@ class TerminalBotHandler:
return self.message_server.send(message) return self.message_server.send(message)
def send_reply(self, message, response): def send_reply(self, message, response):
print(''' print("\nReply from the bot is printed between the dotted lines:\n-------\n{}\n-------".format(response))
reply:
{}
'''.format(response))
response_message = dict( response_message = dict(
content=response content=response
) )

View file

@ -56,18 +56,23 @@ def main():
sender_email = 'foo_sender@zulip.com' sender_email = 'foo_sender@zulip.com'
while True: try:
content = input('Enter your message: ') while True:
content = input('Enter your message: ')
message = dict( message = dict(
content=content, content=content,
sender_email=sender_email, sender_email=sender_email,
display_recipient=sender_email, display_recipient=sender_email,
) )
message_handler.handle_message( message_handler.handle_message(
message=message, message=message,
bot_handler=bot_handler, bot_handler=bot_handler,
) )
except KeyboardException:
print("\n\nOk, if you're happy with your terminal-based testing, try it out with a Zulip server.",
"\nYou can refer to https://zulipchat.com/api/running-bots#running-a-bot.")
sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':
main() main()